Skip to main content

Full text of "SYNC Magazine"

See other formats


$2.50 (USA) 
£1.20 (UK) 


id 
“= 
1 
% 
ж 
ж 
" 


(Л 
i. 
Ф 
(Л 
2 
- 
— 
О 
CO 
X 
N 
| 


Volume 1, Number 4 


la 


INC 


for S 


пе 


The magaz 


David Ahl, Founder апа 
Publisher of Creative Computing 


You might think the term ‘creative com- 
puting’ is a contradiction. How can some- 
thing as precise and logical as electronic 
computing possibly be creative? We think 
itcan be. Consider the way computers are 
being used to create special effects in 
movies—image generation, coloring and 
computer-driven cameras and props. Oran 
electronic "sketchpad' for your home 
computer that adds animation, coloring 
and shading at your direction. How about a 
computer simulation of an invasion of killer 
bees with you trying to find a way of keep- 
ing them under control? 


Beyond Our Dreams 


Computers are not creative per se. But 
the way in which they are used can be 
highly creative and imaginative. Five years 
ago when Creative Computing magazine 
first billed itself as "Тһе number 1 maga- 
zine of computer applications and soft- 
ware, we had no idea how far that idea 
would take us. Today, these applications 
are becoming so broad, so all- 
encompassing that the computer field will 
soon include virtually everything! 

In light of this generality, we take "appli- 
cation to mean whatever сап be done with 
computers, ought to be done with comput- 
ers or might be done with computers. That 
is the meat of Creative Computing. 

Alvin Toffler, author of Future Shock and 
The Third Wave says, `| read Creative Com- 
puting not only for information about how 
to make the most of my own equipment but 
to keep an eye on how the whole field is 
emerging. 

Creative Computing, the company as 
well as the magazine, is uniquely light- 
hearted but also seriously interested іп all 
aspects of computing. Ours is the maga- 
zine of software, graphics, games and sim- 
ulations for beginners and relaxing profes- 
sionals. We try to present the new and im- 
portant ideas of the field in a way that a 14- 
year old or a Cobol programmer can under- 
stand them. Things like text editing, social 


creative 


A REMARKABLE MAGAZINE 


compating 


"The beat covered by Creative Computing 
is one of the most important, explosive and 
fast-changing.” — Alvin Toffler 


simulations, control of household devices, 
animation and graphics, and communica- 
tions networks. 


Understandable Yet Challenging 


As the premier magazine for beginners, it 
is our solemn responsibility to make what 
we publish comprehensible to the new- 
comer. That does not mean easy; our 
readers like to be challenged. It means 
providing the reader who has no prepar- 
ation with every possible means to seize 
the subject matter and make it his own. 

However, we dont want the experts in 
our audience to be bored. So we try to 
pubiish articles of interest to beginners and 
experts at the same time. Ideally, we would 
like every piece to have instructional or 
informative content—and some depth— 
even when communicated humorously or 
playfully. Thus, our favorite kind of piece is 
acessible to the beginner, theoretically 
non-trivial, interesting on more than one 
level, and perhaps even humorous. 

David Gerrold of Star Trek fame says, 
"Creative Computing with its unpreten- 
tious, down-to-earth lucidity encourages 
the computer user to have fun. Creative 
Computing makes it possible for me to 
learn basic programming skills and use the 
computer better than any other source. 


Hard-hitting Evaluations 


At Creative Computing we obtain new 
computer systems, peripherals, and soft- 
ware as soon as they are announced. We 
put them through their paces in our Soft- 
ware Development Center and also in the 
environment for which they are intended — 
home, business, laboratory, or school. 

Our evaluations are unbiased and accur- 
ate. We compared word processing printers 
and found two losers among highly pro- 
moted makes. Conversely, we found one 
computer had far more than its advertised 
capability. Of 16 educational packages, 


only seven offered solid learning value. 


When we say unbiased reviews we mean 


it. More than once, our honesty has cost us 
an advertiser — temporarily. But we feel 
that our first obligation is to our readers and 
that editorial excellence and integrity are 
our highest goals. 

Karl Zinn at the University of Michigan 
feels we are meeting these goals when he 
writes. "Creative Computing consistently 
provides value in articles, product reviews 
and systems comparisons ...in a magazine 
that is fun to read." 


Order Today 


To order your subscription to Creative 
Computing send payment to the appropri- 
ate address below. Customers in the 
continental U.S. may call toll-free to 
charge a subscription to Visa, MasterCard 
or American Express. 

Canada and 
Term | USA Foreign Surface Foreign Air 


1year $20 $29 ог £12.50 $500ог £21 
2 years $37 $55 ог £24.00 %97 ог Ғ41 
3 years $53 $80 ог £34.50 $143ог £61 


We guarantee your satisfaction or we 
will refund your entire subscription price. 

Join over 80,000 subscribers like Ann 
Lewin, Director of the Capital Children's 
Museum who says, “I am very much im- 
pressed with Creative Computing. |t is 
helping to demystify the computer. Its arti- 
cles are helpfu!, humorous and humane. 
The world needs Creative Computing.” 


Greative 
Gorepatirg 


P.O. Box 789-M 
Morristown, NJ 07960 
Toll-free 800-631-8112 
(іп NJ 201-540-0445) 


27 Andrew Close, Stoke Golding 
Nuneaton CV13 6EL, England 


The magazine for Sinclair ZX80/1 users 


Ei | == 


July/August 1981 Volume 1, Number 4 
DEPARTMENTS GAMES AND PROGRAMS 
2 Glitchoidz Report. .................................... 36 Ee ИЕ Nisbet 
ind the clues 
3 SYNC Могев................................. Grosjean 
44 winiBillboard. |. Duke 
4 Letters. oe Make your own sign 
6 РегсерШіопв.................................. Ornstein 
SYNCSUM MACHINE LANGUAGE 
20 Puzzles and Problems....................... Townsend Machine Code Keyboard Scanning............Puerzer 
2 8 Decoding the keyboard 
Crash Сигзог.................................. Truman 
1 6 Screen 5сто ћпд................................ Logan 
46 ЖЕТЕ; везан ње био ров оба в А Third іп a series оп machine language 
STRINGS AND ARRAYS INTERFACING 
11 me TL$ Ғипсіоп............................... Miller | 12 rechniauesotthezxeo.......... ss Onsy 
TL$ for “READ"ing Outputting to asynchronous peripherals 
24 Multidimensional Arrays on the 2Х80........ O'Connell 38 A Parallel іпіегігсе................................ Salt 
Dealing with DIM statements A construction project 
26 TRS and LET А5-А5--В5 onthe ZX80......... Doakes REVIEWS AND RESOURCES 
String handling without TR$ 45 ——— Utasi 
же И asi 
MATH AND MATH GRAPHICS Hardware Review 
22 46 зквом _______._._____. Lubar 
Setting Up Bar Сһагів.......................... Passler 
Visual statistics Hardware Review 
23 Bisection Iteration Square Root Program......... Goins 47 andthe Walls Came Tumbling Down.......... Grosjean 


34 


Find your roots 


Тһе ZX80 Makes the Grade....................... Auer 
Adding and analyzing statistics 


Multiplication Three іп а Row................... Brown 
Test your skill 


Software Review 


НВезоигссев....................................... 


COVER: Young beginners at Creative Computing’s summer Computer 
Camp learning Basic operations on the ZX80 keyboard. Photo 
courtesy Morristown Daily Record. 


incumbent eee не 


Publisher/Editor-in-Chief 
Editorial Director 
Managing Editor 


Associate 
Secretary 


Production Manager 
Typesetters 


Financial Coordinator 
Bookkeeper 
Customer Service 
Order Processing 
Circulation 


MEMBER 


Staff 


Advertiser 


David H. Ahl Are you in SYNC 
George Blank 


Paul Grosjean 


Be a Computer Literate 
Colossal Computer Cartoon Book 45 


Index to Advertisers 


Volume 1, Number 4 


Page 
үз SYNC is published bi-monthly for $10.00 per year 
14 by Creative Computing, 39 E. Hanover Ave.. Mor- 


ris Plains, NJ 07950. Second class postage paid at 


Editor David Lubar Creative Computing Subscriptions Cover 2 Morris Plains, New Jersey 07950, and additional 
Elizabeth Magin Find ZX80 owners 33 entry offices. 
Laura MacKenzie Katie and the Computer 21 
Jean Ann Vokoun Lamo-Lem 9 Postmaster: Send address changes to SYNC, P.O. 
Maureen Welsh L.J.H. Enterprises 23 Box 789-M, Morristown, NJ 07960. 
William L. Baumann Macronics 21 
Patricia Kennelly Maples 33 Subscriptions in USA: 6 issues $10; 12 issues $18: 
Ralph Loveys New England Software 13 18 issues $24. UK and foreign airmail subscrip- 
Ruth Coles Peripherals Plus 33 tions: 6issues £10; 12 issues £18; 18 issues £25. Call 
Frances Miskovich Softsync 23 (800) 631-8112 toll-free (іп NJ, 201-540-0445) to 
Dorothy Staples SYNC Cover 4 begin your subscription. 
Carol Vita Creative Computing T-Shirts Cover 3 
Zeta Software 21 Copyright 1981 by Creative Computing. All rights 


July/August 1981 


reserved. Reproduction prohibited in any form. 


neport 


The GLITCHOIDZ REPORT will pass 
on to our readers errors, problems, and 
other Glitchoid activities which have been 
discovered. We welcome your contribu- 
tions to this column. 


GOTO Lines 

Some readers have asked about a line 
such as GOTO 450 when the program 
does not have a line 450. In the Z X80 this 
does not stop the program or confuse the 
computer. The ZX80 will search for the 
line and, failing to find it, go on to the 
next line in the program after 450. In 
effect, it jumps over the GOTO command 
line in such cases. 


Castle Doors (1:30) 
Correct: 
48 IF D=2 THEN LET A=RND(30) 
62 IF D=5 THEN LET A$=“ZOMBIE” 


Draw a Picture (1:33) 

Some readers have reported difficulties 
with this program, but it will run as printed. 
Pay especial attention to the last paragraph. 
When the program is entered and RUN, 
you are to respond to the prompt by 
entering the coordinates of the square 
you want to fill with a graphics symbol. 
You are then to respond to the prompt 
ENTER CHAR CODE with the number 
of the symbol you want as shown in column 
3. Erasing may be done by entering 0 to 
erase the previous character or by entering 
the coordinates again and then the new 
character. 


How to Produce a Display File 
(2:15, col. 13 
A full screen suggestion: 
40 FOR J=1 TO 21 
Correct: 
60 FOR I=1 TO 30 
70 PRINT * >; (1 sp.) 
(2:15, col. 1) 

Continue adding dummy lines until line 
10 is scrolled off the screen. Then delete 
the dummy lines by entering the line 
number and NEWLINE before entering 
the loader program. 

(2:15, col. 2) 
40 IFA «1 OR > 300 THEN GOTO 30 


Truth in Programming (2:19, col. 1) 
20 IF X THEN LET Т=Т+1 


2 


Glitchoidz 9%: 


е 


9 * x 3 0 


SOLS 


(098) — 
КОВ 


god pA? 


EN SS uec e... 
i iJ 


Game of Life (2:29) 

Change: 450 NEXT I 

Add: 460 FOR 1=9 TO 55 

The graphics given in the program do 
not produce the * in the square. Hopefully 
the * makes it easier to see the squares 
being referred to. For those who want to 
use the * in the display, change the 
character number 128 to 222 in lines 120 
and 500. 

Some readers have pointed out that 
the game does not follow the rules in the 
article. Reader Walter Bacon has proposed 
program changes to bring it closer to the 
rules (see Letters). 


Artillery (2:27) 

Readers with 1K have found that the 
game fills the memory rather quickly. You 
can increase the memory available for 
play by trimming down the PRINT state- 
ments to very brief prompts or try Reader 
Joe Dell'Orfano's program amendments 
(see Letters). 


Tic Tac Toe (2:22) 
Add: 445 CLS 


More Truth in Programming (3:7, col. 3) 
Correct: 
IF NOT (X <5 AND Y< 8)... 


Black Hole (3:9) 
Correct: 
75 IF S<1 OR $ >9 THEN GOTO 70 
See the Letters for suggestions for 
trimming this to 1K. 


Auto-Display-Changing (3:14) 

Dr. Logan reports a bug that occurs 
because of variations in TV sets: “Some 
users may find it necessary to use other 
values in line 64. 

64 POKE A+24,3 ог 5 
in order to get better timing.” 


Variable Conversions (3:26) 
Correct: 
113 IF X=-27 THEN GOTO 116 


Forest Treasure (3:34) 
Correct: 

30 PRINT ‘g’; (shift A), or 

30 PRINT CHR$(128) 

490 delete % 


8K Basic ROM and 16K-Byte RAM Pack 
(3:37) 

As a number of readers observed, the 
actual ROM they received differs somewhat 
from our article. Between the time we 
received the materials and the actual 
production of the 8K ROM a few changes 
were made. 

The following 
omitted: 

DATA 
DRAW m,n 
NEW n 

READ у 
RESTORE 
UNDRAW m,n 


These commands were added: 
LPRINT Prints a string on the printer. 


commands were 


L LIST Lists the program on the 
printer. 

COPY Prints the entire screen on 
the printer. The printer is 
capable of printing all the 
characters including 
graphics. 

FAST On the ZX81 there are two 
modes of operation. 

SLOW On the ZX80 8K keyboard 
these do not function. 

(3:38) 


16K RAM Pack: A separate power 
supply is now being provided. 


The ZX80 Keyboard 
(3:42) 

The author is David Ornstein, 25 Shute 
Path, Newton Centre, MA 02159. 
(3:44) 

Listing 1 is copyrighted by Sinclair 
Research. 


Graphics Surprises (3:22) 

The author is James H. Parsons, 1921 
Flintlock Terrace West, Colorado Springs, 
CO 80918. 


SYNC Magazine 


зло | = | $ = — ___6_(___ 


Раш Grosjean 


ZX81 — The Family Increases 

A number of people have asked us 
whether we are going to include the ZX81 
in our coverage. As our changed cover 
shows, the answer is a definite YES. 

With the multiplication of the ZX80 
family and the availability of new ROMs 
and RAMs, our readers want to know 
what the machine requirements of our 
programs are. If you are planning to send 
us an article or program that you have 
developed, be sure to state the minimum 
machine requirements for your, program 
on a separate line below the title. When 
we are referring to the general family or 
discussing the family in areas where the 
ROMs and RAMs are not important, we 
will say simply the “Z X80,” but where the 
ROM and RAM are important we want 
to include that information. 


PERCEPTIONS 

In this issue we are introducing the 
column PERCEPTIONS by David Ornstein 
(p.6 ). David has already contributed to 
SYNC through his work on the schematic 
of the Z X80 in issue 1, “Video Modifica- 
tions for the ZX80” in issue 2, and “The 
ZX80 Keyboard” in issue 3. 

Though he is Technical Services 
Manager for Sinclair Research Limited 
(U.S.), we must hasten to point out that 
the views expressed in his column will be 
strictly his own and in no way will represent 
Sinclair Research. 


SYNCSUM 

We are especially pleased with the first 
contribution of PERCEPTIONS to SYNC 
readers and authors in the concept and 
programs for the SYNCSUM. This is a 
method of checking whether you have 
entered the program correctly. If you are 
submitting an article, we ask you to include 
the SYNCSUM at the end of any program 
listing. 


July/August 1981 


Spaces in PRINT Statements 

Since we do not have a symbol on the 
ZX80 that marks clearly the empty spaces, 
sometimes problems arise in entering 
programs and getting them to work because 
the correct number of spaces in the PRINT 
statements is not always clear. When we 
receive a program done on a typewriter 
or a printer, we can usually figure out the 
number by counting the letters in the line 
above or below since each letter takes up 
the same amount of space. However, this 
is not always accurate because typo- 
graphical errors can occur even in leaving 
spaces. Another problem comes up when 
we typeset programs. On the type setting 
machine letters vary in the amount of 
space they take up in the line and the 
spaces also vary in order to make the 
right hand margins even. So counting does 
not work. We have tried to handle this 
problem up to this point by indicating the 
number of spaces in a side note. Beginning 
with our next issue, we will be using a 
symbol to indicate spaces where these 
affect the running of the program. 

If you are submitting a manuscript, we 
are asking you to indicate all spaces in 
the PRINT statements except the obvious 
ones between words by using the symbol 
7. We have chosen this because it is found 
on almost all typewriters, and it is not 
used on the ZX80 family of computers. 
We will use a different symbol in $YNC 
articles, but, even if we slip up, # will not 
cause any programming errors since it 
cannot be entered. 

If in running a program you are sure 
that you have entered it correctly but it 
still does not work, check the number of 
spaces in any PRINT statements. You 
might experiment by changing these. 


MicroAce II???? 

Contrary to some reports, MicroAce 
is not planning at the present time to 
offer a MicroAce II. When the present 
stock of kits is exhausted, the MicroAce 
computer will no longer be available from 
MicroAce. The company goal will be to 
offer equipment to upgrade the machines 
already sold. An 8K ROM and a flicker 
free video board (which requires 8K ROM) 
will be available by the time you receive 
this issue of SYNC. The RAM capacity 
will be expandable by two options: a 4K 
RAM and a 16K RAM. These are planned 
for the fall. 


SYNC Subscribers Pass the 6000 Mark 
At the end of June our subscription list 
totaled 6135 subscribers with 1532 outside 
the U.S. California leads the list with 13% 
of the total, followed by New York with 
7%, and then by Illinois, Texas, and Massa- 
chusetts with about 4% each. Outside the 
U.S. the United Kingdom leads the list. 


А P.S. from Alger Salt 

Readers of Alger Salt's “А Parallel 
Interface for the ZX80/MicroAce" should 
note the following P.S. which arrived after 
our layout was completed: 

After reading the article "The ZX80 
Keyboard" in the May/June issue of 
SYNC I learned that the keyboard is an 
input device that is addressed by any 
even address. This accounts for the diffi- 
culty I encountered when trying to read 
from port A on the PIO. The problem 
can be avoided by using address line A2 
instead of А0 to select the А or B port. 
That is, connect the A/B SEL line on the 
РІО to a different address line than AO. 
Then use only odd addresses when 
addressing the PIO, i.e., addresses with 
AQ = 1. 


letters ООО 


Gauntlet and USR(47) 


Dear Editor: 

My Gauntlet program in your May/ 
June issue can be greatly improved by 
using the technique described on page 6 
of the same issue. On that page, Hasse 
Taube says that USR(47) will return the 
end of variables address. But the end of 
variables is right next to the start of the 
display file. That makes my machine 
language routine unnecessary. 

The machine language routine made 
entering the program difficult and listing 
the program dangerous. But if you change 
line 900 to: 900 LET D=USR(47)+2, then 
you can ignore the subroutine loader and 
decimal listing and also delete line 1. 

This is another example of how SYNC 
helps get the most out of the ZX-80. My 
thanks to Michael Kirkland, Hasse Taube 
and, of course, to SYNC. 


Ken Berggren 
104 Ridgeway Ave. 
Louisville, KY 40207 


Widgeteconomics 


Dear Editor: 

. . . I greatly enjoy your magazine; 
however, I have found a few problems. In 
running the Widget program I have never 
been able to even break even. It is a 
challenge just to keep from going bankrupt. 
Is the program listing just advertisement? 

Another thing I would like to see in 
your future articles is how to convert 
either mechanically or through a machine 
code subroutine the screen to active instead 
of going blank during runs. 


Richard McDaniel 
PO Box 71 
Glasgow, VA 24555 


Ed. —A number of readers of Widget 
have found it quite challenging. See Reader 
Васоп 5 letter below. It seems that to 
remain solvent and become a successful 
capitalist, you must make some minor 
program changes. 

Гйе conversion you ask for would cost 
more than the original computer, according 
to our sources. So it does not seem practical 
at this point. 


4 


Dear Editor: 

... Widget - NEAT PROGRAM! No 
mistakes, but it is impossible (mathemati- 
cally) to ever progress from those starting 
conditions. You can only minimize your 
losses to last as long as possible before 
bankruptcy overtakes you. The game is a 
good challenge if you start with two plants 
(or other assets like inventory)... 

Game of Life. You printed a program 
from Thirty Programs for the Sinclair ZX80 
ІК. The book Addendum Page makes 
corrections in lines 450 and 460 (See 
Glitchoidz Report). However, even with 
these corrections the program does not 
follow the logic rules although it does 
run. To change the program so it follows 
the rules make the following corrections: 


320 IF ((1+1/7) AND 7)=0 THEN GO 
TO 350 

340 IF ((1-1+(1-1)/7) AND 7)=0 THEN 
GO TO 360 

360 FOR J=6 TO 8 

400 IF (J*R=-8 OR J*R=6) AND ((1-1+ 
([-1)/7) AND 7)=0 THEN GO TO 
420 

405 IF (J*R=8 OR J*R=-6) AND ((1+1 
/7) AND 7)=0 THEN GO TO 420 


If you do this and the publisher's changes 
in 450 and 460, the program will follow 
the rules in the article. 


Walter W. Bacon 
RR 7, Box 68 
Hopewell Junction, NY 12533 


Ed.— For those who cannot abide by 
the decisions of the free market place 
and face bankruptcy fearlessly, a bit of 
Widgeteconomics can be performed by 
tinkering with the program to improve 
the market position. According to my 
program advisers, increase P in line 10 
and/or change line 640 to read LET М=М- 
20*P-15. You can also try a number lower 
than 15. 


Artillery and Black Hole 


Dear Editor: 

The Artillery game depletes my 1K 
of RAM after about 5 or 6 turns. After 
searching through the listing for a mistake 
in my typing, I came up with the following 
changes: 

Omit: Line 140 

Change line 320 to: 320 GO SUB 150 
Add: 80 DIM S(21) 

The program should now work without 
any difficulties. 

Also, the program Black Hole by Bill 
Eckel will run in 1К of RAM if the following 
changes are made: 

Omit 5, 14, 16, 18, 30, 32, 34, 1025, 1130 & 
1140 


100 LET B=S+ 1-2*(S/2) - 2*(S/6) 
+4*(5/8)-3*(5/9) 

110 GO SUB 980 

120 LET B=S+3-2*(S/2)+(S/3)+3* 
(S/4)-4*(S/5) +5*(S/6)-5*(S/7) 
+2*(S/8)-5*(S/9) 

130 GO SUB 980 

140 LET В=5+4-6%(8/2) + 5%(8/3)- 
(5/4)--5%(8/5)-6%(8/6)--7%5/7) 
-2*(S/8) +2*(S/9) 

150 GO SUB 980 

160 LET B=0 

170 IF S=5 THEN LET B=8 

180 GO SUB 980 

960 GO TO 25 


1075 IF Ха +5)=0 THEN RETURN 


Or, as David Lubar might want to write 
it: 

100 LET B=-2*(S=1)-(S=2)-2*(S=3) 
-(S=4)-2*(S=5)-3*(S=6)-4*(S=7) 
-7*(S=8)-5*(S=9) 

120 LET B=-4*(S=1)-3*(S=2)-5* 
(S=3)-7*(S=4)-4*(S=5)-9*(S=6) 
-5*(S=7)-9*(S=8)-6*(S=9) 

140 LET B=5*(S=1)-6*(S=3)-6* 
(S=5)-8*(S=7)-8*(S=9) 

Replace lines 160 and 170 with: 

160 LET B=-8*(S=5) 

Lines 100,130,150, and 180 remain as 

in the first change. 


As you can see, David Lubar’s article 
about Boolean operations has been used 
to a great extent in shortening Black 
Hole. 


Joe Dell'Orfanio 
122 Weaver St. 
Greenwich, CT 06830 


SYNC Magazine 


Dear Editor: 

Bill Eckel’s Black Hole (SYNC 3:8) can 
be compacted to fit in less than 1K of 
memory, thus making it fit neatly into an 
unexpanded ZX-80. The following con- 
versions should work: 


Changes: 20 LET X(5)— -1 

44 IF X(D THEN PRINT 
иж. 

46 IF NOT X(I) THEN 
PRINT 0; 

78 | IF NOT X(S) THEN GO 
TO 70 

980 IFNOT X(B) THEN GO 
TO 986 

983 IF X(B) THEN LET 
X(B)=0 

986 LET X(B)= -1 

1010 IF Х(І) THEN GO TO 
1050 

1050 IF X(5) THEN RETURN 

1070 IF NOT X(I) THEN 
RETURN 

1100 IF NOT X(I) THEN 
RETURN 

1120 PRINT *YOU WIN" 


I used the first conversion as it was my 
own, and I hadn't yet read Mr. Lubar's 
article. I have found no problems in the 
playing of Black Hole after the conversion 
was made. I have also found that any one 
of the possible solutions is actually two 
solutions... just reverse the order. Happy 
Star-Shooting. 


Mark Kleinman 
4228-D FCN 
McGuire AFB, NJ 08641 


Basic Computer Games 
on the ZX80 


Dear Editor: 
Please tell me if the programs in Basic 
Computer Games and More Basic Com- 


puter Games work on the Sinclair ZX80 
and VIC-1001. 


A. Samereu 

4946 Dornal 

Montreal, Quebec H3W-1W2 
Canada 


Ed. — These programs will not work directly 
on the ZX80 for two reasons. First, they 
must be translated, that is, adapted to the 
specific form of Basic that the ZX80 uses. 
This is not difficult after you get some 
experience in programming and after you 
put SYNC articles to work for you. Second, 


July/August 1981 


many programs even when translated will 
require more than 1K RAM. So before 
you enter a program, you can give it a 
rough check for size by comparing it to a 
1K program printed in SYNC. If you want 
to be more precise, you can count the 
bytes in the translated program. The line 
entry requires 2 bytes; each keystroke in 
the line content counts as one; the NEW- 
LINE entry adds one more. 


LED Fringe Benefit 


Dear Editor: 

I added the LEDs to monitor tape input 
as described by Cecil Bridges in the initial 
issue of SYNC. An additional advantage 
of this modification that he did not mention 
is that it eliminates the need to disconnect 
the ear cable on the recorder in order to 
position a tape for program loading (if 
you have a tape recorder with a digital 
counter). Simply advance the tape to the 
appropriate number on the counter, type 
LOAD, start the recorder, and when the 
red light goes out type NEWLINE. 


William H. Caskey 
1112 Pake Lane 
Morris, MN 56267 


Memory Mapping 


Dear Editor: 

The one thing ГА really like for your 
editors to address is how we get information 
into the ZX80 from the outside world 
using memory mapped input. I’m afraid 
to use the same approach for input that I 
used for output (i.e., writing to a nonexistent 
ROM address) because when I PEEK(4097) 
I get 64 decimal. This implies to me that 
somebody is on the data bus (at least D5). 
I'm afraid to put anything on the data bus 
for fear of having two chips on the bus at 
the same time and damaging someone. 
Of course I don't have a circuit schematic 
with the 7Х80 so I can't really decide 
whether or not the risk exists or whether 
D5 just appears high because one tristate 
doesn't clamp all the way. Can you sell 
me a schematic for the ZX80? 


William Byrne 
2 Cypress Dr. 
Wichita, KS 67206 


Ed. – А suggestion from David Ornstein: 
Put the memory map input port in any 
address between 12 and 16K. 

Schematics of the ZX80 are available 
at no charge from Sinclair Research 
Limited, 50 Staniford St., Boston, MA 
02114. 


SYNC Coverage 


Dear Editor: 

. . . I hope that all the new products 
coming out will not affect your policy of 
sticking to the basic machine. Anyone 
with new ROM can, I think, easily translate 
old ROM programs, whilst the converse 
is not always possible. I hope that you 
could follow the ideas of Interface the 
National ZX80 Users Club magazine over 
here and produce mainly ІК programs 
with an occasional 4K or more. 

One thing I would like to see in SYNC 
is more attention given to PEEK, POKE, 
and USR. Most people can devise a 
program just using Basic, but if you have 
no knowledge of machine code or the Z- 
80, such as Ken MacDonald's EXCEL- 
LENT space intruders program advertised 
p. 19 [issue 1], are unintelligible—all I 
know is that they work... 

I hope the 7Х80... catches on over in 
the States as well as it has here; if the 
example set by the TRS-80, PET and 
APPLE is anything to go by then we're in 
for a good deal of excellent American 
software — especially from Creative Com- 
puting! 


Richard J. Barton 
12 Mill Lane 
Camblesforth, 
Selby 

North Yorks 
ҮО8 SHW 

U.K. 


Ed. — While the scope of SYNC must grow 
to meet the needs of our readers as they 
also grow in knowledge of the machine 
and expand their equipment, we will not 
leave behind the people with the basic 
ZX80 nor those people who are new to 
computing. Again, authors take note. 
PEEK, POKE, and USR are among the 
most frequently requested topics for 
articles. 


Currently Technical Services Manager, 


David Ornstein has been with Sinclair since the 
opening of its U.S. office. He has been involved with 
Sinclair's technical hotline, technical writing, and 
machine servicing. His primary interests are in 

the areas of software and hardware R & D, and 


system integration. 


His secondary interests are reading (Frank Herbert), 


listening (Pink Floyd) and sharing 


SYNCSUMs 


One day, I was typing a system-check 
program into our computer. I took four 
and a half hours to enter the program. As 
I was about to run it, an awful thought 
occurred to me: What if I had made an 
error in my typing? Since the program 
had access to all parts of the system, a 
typo could be fatal. I decided to check it 
against the listing . .. once. Then I ran it. 
The end result— that I overwrote the sys- 
tem disk—is irrelevant. But what is 
important is this: /f the program listing 
had included the program's SYNCSUM, | 
would have known better. 

What is a SYNCSUM? A SYNCSUM is 
what is known as a checksum, or, rather, 
a modified version of a checksum. The 
checksum is a method of checking to see 
whether a program has been entered cor- 
rectly by letting the computer add up all 
the bytes in a program. To use this error- 
checking method, you simply compare 
the checksum of the original program 
with the checksum of the program you 
have entered. If the numbers are not the 
same, you have made an error in entering 
the program. If the numbers are the 
same, the chances are about 90% that 
you have entered the program correctly. 

In the ZX80, a certain area of memory 
is used to hold the current program. This 
area begins where the area for system 
variables ends. For the 4К ROM, this 
address is 16424 decimal (4028 hex); for 
the 8К ROM, 16509 decimal (407D hex). 
А system variable points to the first byte 
after the program area. The 4K and 8K 
ROMs format memory differently. In a 
4K system, therefore, this variable is 
VARS (which points to the first byte of 
the VARiable Storage area), but in an 8K 
system, it is D-FILE (which points to the 
first byte in the Display FILE). These 
variables are stored at locations 16392 
(4K) and 16396 (8K), respectively. 


6 


ПпЕГГЕрІГІ о 


David Ornstein 


The assembly language program, 
shown in listing 1, is used to generate the 
current program’s SYNCSUM on a 4K 
system. The corresponding program for 
an 8K system is shown in listing 2. You 
will notice that it is not adding all the 
bytes, but XORing them together. This is 
the modification of the standard check- 
sum method referred to earlier. You will 
end up with a number which is less than 
256. 

To use the SYNCSUM program on a 
Basic program requires that the SYNC- 
SUM program be resident (i.e., in mem- 
ory) all the time. This can be accom- 
plished first, by reserving some memory 


(RAM) such that Basic will not tamper 
with it, and, second, by loading the 
SYNCSUM routine into this area. List- 
ings 3 and 5 are programs to reserve the 
required amount of memory, 27 bytes. 
They should be used on 8K and 4K sys- 
tems respectively. Listings 4 and 6 are 
programs to load the machine language 
SYNCSUM generation program into this 
previously reserved memory space. 
These programs should be run at the 
beginning of any session of computer use 
when you may want to know a programs's 
SYNCSUM. From the time they are run 
until the computer is turned off, obtain- 
ing the SYNCSUM 15 simple: type 


Label Hex Assembly Code Comments 
4KSSUM: 212840 LD HL,16424 ;HL-Start 
ED5B0840 LD DE,(VARS) ;DE=Stop 
0600 LD B,00 “В--00 (Result Accumulator) 
LOOP: 7С LD A,H И HL=DE then XORNXT 
BA СРО 
2008 ІК NZ,XORNXT 
7D LD A,L 
BB CPE 
2004 JR NZ,XORNXT 
DONE; ;else done 
68 LD L,B slow byte returned is SY NCSUM 
2600 LD H,00 shigh byte is 00 
C9 RET 
XORNXT: ХОК the next byte into the 
;Result Accumulator. 
78 LD A,B "бес current RA 
AE XOR (HL) "ХОК it in 
47 LD B,A ;put back result into RA 
23 INC HL ;bump pointer 
18ЕЕ JR LOOP ‚ро back for next byte 
Listing 1. 


SYNC Magazine 


PRINT USR(x), where x = your memory 
size (for example, 1024, 2048, 16384) - 27 
+ 16384, followed by NEWLINE as always. 
Thus x will equal 17381 for 1K, 18405 for 


2K, and 32741 for 16K. 
Enter (or LOAD) the RSV program 


(listing 3 or 5) and then RUN and NEW- 
LINE. The 4K program will prompt you 
for MEMORY SIZE?" Enter your memory 
size (1024, 2048, 16384) and NEWLINE. 
Next enter (or on 8K systems only, LOAD) 
the LDR program (listing 4 or 6). On a 4K 
system LOADing the LDR program after 
using RSV will cancel the effects of running 
the RSV program. 

Press RUN and NEWLINE. Again the 
4K program will prompt you for “МЕМ- 
ORY SIZE?" Again enter it and NEWLINE. 
The 4K "MEMORY SIZE?" prompt will 
return to the screen, but hit NEWLINE 
and you will return to program mode. 
The SYNCSUM routine is now resident. 

On an 8K system, type NEW and NEW- 
LINE. On 4K systems, as noted earlier, 
using the NEW command will delete the 
SYNCSUM routine from memory. There- 
fore, to clear out the 4К LDR program, 
you must delete each line individually. 
To delete, e.g., line 10, type 10 and 
NEWLINE. Repeat until the whole program 
is gone. 

You can now begin entering your pro- 
gram. Once again, if you have an 8K 
system, you can LOAD your program. 
With 4K you must type in each line 
individually, as LOADing will destroy the 
SYNCSUM routine. You can now obtain 
the SYNCSUM at any point along the 
way via the PRINT USR (x) command 
(see above for the size of x). When you 
have finished and you are sure your 
program is correct, call for the SYNCSUM 
for the entire program. Write it down at 


Label Hex Assembly Code Comments 
8KSSUM: 217040 LD HL,16509 ;HL=Start 
ED5B1240 LDDE,(D-FILE)  ;DE-Stop 
0600 LD B,00 ;В=00 (Result Accumulator) 
LOOP: ТС LD AH ЈЕ HLADE then XORNXT 
BA CP D 
2008 JR NZ,XORNXT 
7D LD A.L 
BB CPE 
2004 JR NZ,XORNXT 
DONE: ;else done 
68 LD C,B slow byte returned is SYNCSUM 
0600 LD B,00 shigh byte is 00 
C9 RET 
XORNXT: ;XOR the next byte into the 
;Result Accumulator. 
78 LD A,B ‘Get current RA 
AE XOR (HL) ‚ХОК it in 
47 LD B,A ;put back result into RA 
23 INCHL ;bump pointer 
18ЕЕ JR LOOP ;go back for next byte 
Listing 2. 


end of your program for future reference. 
Be sure to include it after the end of any 
programs submitted to SYNC. 

This method will also work just as well 
with the ZX81 since it uses the SK ROM. 


I hope this idea is as helpful to ZX80 
owners as it is to the rest of the computer 
world. 

Until next issue, same relativistic time 
period, same non-euclidian universe. "g 


5 LET R=27 


10 PRINT "MEMORY SIZE ?" 


20 INPUT M 


30 LET M=M-R+16384 
35 POKE 16999, 33 


40 РОКЕ 17000,М 


50 РОКЕ 17001,М/256 
60 РОКЕ 17002,195 


10 LET R=27 [the number of bytes to reserve] 70 POKE 17003,107 
20 LET КАМТОР=РЕЕК (16388) +РЕЕК (16389)*256-В. 80 POKE 17004,2 
30 POKE 16388, ВАМТОР-256*ТМТ (RAMTOP/256) 90 LET K=USR(16999) 
40 POKE 16389, INT (RAMTOP/256) 
50 NEW 
Listing 5: 4K ROM RSV 
Listing 3: 8K ROM RSV. 
10 КЕМ 212840ED5B084006007CBA20087DBB 
2004682600C978AE472318EE 
15 LET В=27 
10 REM 217040ED5B124006007CBA20087DBB 20 PRINT "MEMORY SIZE ?" 
2004680600C978AE472318EE 30 INPUT M 
20 LET ВТ=РЕЕК (16388)+PEEK (16389) 256 40 LET RT=M-R+16384 
30 FOR В=0 TO 26 50 FOR B-0 TO 26 
40 LET Х= ( (РЕЕК (16509+5+8В*2)-28)*16+(РЕЕК 60 LET X-((PEEK(1642443-B*2)-28)*16--(PEEK 


(16509--5--В%2-1)-28)) 
50 РОКЕ ВТ+В,Х 
60 МЕХТ В 


Listing 4: 8K ROM LDR 


July/August 1981 


(16424+3+В*2+1)-28)) 


70 POKE ВТ+В,Х 


80 МЕХТ В 


Listing 6: 4K КОМ LDR 


Machine Code Keyboard Scanning Program 


Visions danced in my head! Visions of 
a completely controlled Amateur Radio 
station. 

Imagine! A microprocessor-controlled 
system that would translate a Morse Code 
message and display it on the monitor, 
translate a message into Morse Code and 
transmit it at a pre-determined code speed, 
control a rotor to allow a beam to follow 
the Oscar satellites (satellites developed 
by an international Amateur Radio group 
for its exclusive use), and automatically 
log all the stations that I had communica- 
tion with. The possibilities are endless. 

I explained to my wife that a personal 
computer could do more than play games. 
(How else was I to persuade her that a 
computer was a necessary purchase?) 1 
listed all the useful functions. At first she 
listened to my pipedreams in disbelief, 
but as my plans grew more detailed and I 
gave rational explanations of how my ideas 
could be accomplished, she became inter- 
ested, then impressed. 

My immediate interest in a computer 
was to develop a Morse Code transmit- 
receive converter. Then, when more 
memory became available, it would grow 
into the self-contained control system I 
had always envisioned. 

My MicroAce 2K kit arrived, and it 
took less than a week to assemble. Finally 
I was ready to program a task. But wait, a 
good functional check of the system was 
in order. Why not program a few games? 
Bombardment is fun, and Depth Charge 
adds even more challenge. The new issue 
of SYNC contains an enjoyable behind 
the Castle Doors game, and I have got to 
try the “Draw a Picture” program. Two 
months later enough games had been 
played on the system to functionally check 
an IBM 370. 

“Okay,” My wife said. “You were right. 
Personal computers are useful. I mean, if 
you're ever stuck in a dungeon, at least 
you'd know which door to choose." 

I chuckled at this but realized she had 
a point. Computer games can be a trap. 


Bernard Puerzer. 3209 So. Kinnickinnic Ave.. 
Milwaukee. WI 53207. 


8 


My initial project was being ignored. It 
was time I got busy. 

I felt that the Morse Code transmitter 
portion of my project would be the easiest 
since I would need additional circuitry if 
I wanted to receive Morse Code and 
translate it. The computer, as it stands, is 
not equipped to convert the output from 
the receiver into a digital waveform. Due 
to obvious memory constraints, the pro- 
gram has to be done in machine code. My 
plan was to read the keyboard input, find 
the input by consulting a look-up table, 
then convert it to a Morse Code type 
digital output which would clock a relay 
(on the transmitter). A software keyboard 
buffer is needed to allow the operation to 
‘type ahead’ of the transmitted output, 
and a driver subroutine is needed to clock 
the relay at the desired code speed. The 
typed input should also be displayed on 
the monitor. This can be accomplished 
within the MicroAce 2K memory if the 
code is written properly. 

The first stumbling block came when I 
tried to read the keyboard input, using 
machine language code. 


The Problem 

To read the input in Basic, an input 
statement is used, but the INPUT command 
looks for either a number or a letter and 
cannot be used to accept both randomly. 
I could not use it for my application, and 
other programs may have a similar problem. 
To read a key on the keyboard using one 
Basic routine would use up too much 
memory, and I doubt that it is even possible. 
Therefore, it is machine code all the way! 

Even a person with no interest in Morse 
Code could find the keyboard input routine 
interesting since it has many other appli- 
cations. If nothing else, it provides a better 
understanding of the Sinclair/MicroAce 
hardware. 


The Solution 

I began by studying the schematic to 
understand how the keyboard is read by 
the software. As it turns out, both the 
Sinclair and MicroAce use the same 
technique. The keys are wired in a matrix 


Bernard Puerzer 


configuration, and the rows of the matrix 
are connected to the Z-80 address lines 
А8-А15, while the columns are connected 
to the Z-80 through a latch that is energized 
by the KEYBD signal (active whenever 
an I/O instruction is executed). When a 
key is depressed, the address line for the 
row of the key and the data line for the 
column of the key are connected. If the 
address line is low at that instant, the data 
line will be pulled low. Therefore, the Z- 
80 will analyze the data lines after a known 
address is issued with an I/O instruction 
to determine if a specific key was 
depressed. 

If all the address lines A8-A15 were 
low, the Z-80 could not tell which row 
caused the data lines to change. So to 
scan the keyboard, each I/O instruction 
must have only one address line low at a 
time to determine the exact key that was 
depressed. 


The Machine Code Monitor 

Understanding the technique, I pro- 
ceeded to write the machine code to 
decode the keyboard. Although I tried to 
keep the code as efficient as possible, it is 
still almost 100 bytes of instructions. Typing 
in this many POKEs did not seem much 
of a challenge so I wrote the following 
program in Basic: 


5 LET MARK=0 
10 PRINT “ENTER STARTING 
ADDRESS” 
20 INPUT A 
30 PRINT А; “ (1 sp.) "; PEEK (A) 
40 INPUT B 
60IFB 255 THEN GO TO 130 
70 POKE A,B 
80 PRINT A; “ (1 sp.) ”; PEEK (A) 
90 LET MARK=MARK +1 
100 IF MARK 10 THEN GO TO 110 
105 CLS 
107 LET MARK = 0 
109 PRINT А; “ (1 sp.) ”; PEEK (A) 
110 LET A = А+1 
120 GO TO 30 
130 STOP 


Figure 1. 


SYNC Magazine 


This program allows easy loading of 
sequential memory locations. When it 
begins, it asks for the starting address, 
entered in decimal. The program then 
displays the address and its current memory 
contents. 

Enter the new contents in decimal, 
followed by a return. The program displays 
the new contents and then automatically 
increments to the next location, displaying 
the address and current contents. Continue 
entering your machine code program. 
When that is completed, enter a number 
larger than 225 to stop the monitor 
program. 

I am sure you will find this method 
much easier to use than entering a POKE 
instruction for every machine code instruc- 
tion to be loaded. Since so much machine 
code is written in hexidecimal notations 
іп the ‘real world, a good modification to 
this monitor would be to allow the memory 
contents to be loaded by entering the 
number in hex notation. Since this would 
require entering the numbers (0-9) and 
letters (A-F), a keyboard input program 
such as the one to be described would be 
required. Now that we have an easy way 
to enter machine code on our Sinclair/ 
MicroAce the rest is a piece of cake. 


TZ 


CRAPS 


July/August 1981 


BET THE PASS LINE (WITH ODDS), HARDWAYS, THE FIELD, 
BIG 6 & 8, ETC., (WITH RULES). USES LAS VEGAS ODDS. 


BLACKJACK 


USES FOUR DECKS. SHUFFLES AUTOMATICALLY. PLAY 
AGAINST THE DEALER. BLACKJACK WINS 17-1. GRUB- 
STAKE KEY WHEN YOU GO BROKE! 


NOW MG BSS 
Dg GA REAR, 


I have not yet devised a clean way of 
saving long machine code programs on a 
cassette tape, but I did find a technique 
that works. If you set up a few DIM 
statements in the beginning of the monitor 
program to dimension a few arrays with 
variables not used in the program, the 
system will ‘reserve’ memory locations for 
these arrays. The machine code can now 
be loaded, and, when the SAVE command 
is executed, the Basic program, including 
the arrays, will be saved. With some luck, 
the machine code program will reside in 
the ‘reserved’ space and be saved. When 
the program is downloaded from tape and 
re-run, be sure to use the GO TO and not 
the RUN instruction to begin the program, 
or the array space will be erased. 


Keyboard Input Program 

The program, as written, resides in 
memory locations 17401-17497. If this is 
not convenient on your system, the pro- 
gram can be re-located easily enough by 
changing a few of the instructions that 
reference memory. 

When the program is run, the code of 
the depressed key is placed in memory 
location 17400. Therefore, a PRINT CHR$ 
(PEEK(17400)) command will display the 
key depressed on the keyboard. Other 
uses of this code can be devised. 

As the program is being executed, it 


LAMO-LEM PRESENTS: 


| A NIGHT IN LAS VEGAS 


FOUR COMPUTER GAMES FOR THE ZX80 AND MICROACE. 


ROULETTE 


NUMBERS FLASH PAST UNTIL A WINNER COMES UP. BET 
THE NUMBERS, ODD/EVEN, RED/BLACK, О, OO, COLUMNS, 


DOZENS, ETC... 


GRAPHICS. 


ALL FOUR GAMES ON ONE CASSETTE, WITH MANUAL, MINIATURE LAYOUTS, CHIPS, AND FULL COLOR 
KEYBOARD OVERLAYS. FOR ENTERTAINMENT ONLY. REQUIRES 4K BASIC AND 1K MEMORY OR MORE. 


1 ALSO FROM LAMO-LEM: THE CHEST OF CLASSICS. FOUR CLASSIC 

| COMPUTER GAMES. LIFE, LUNAR LANDER, MINDMASTER, AND K-TREK 

4 (WITH PHASORS, SCANNERS, VIEW SCREEN, & WARP DRIVE). 

] CASSETTE, MANUAL, CHARTS, OVERLAYS, & MORE. 4K ROM, 1K RAM, $9.95. 


SEND FOR OUR CATALOG OF ZX80, MICROACE, APPLE, AND TI 57, 
58, & 59 PRODUCTS, INCLUDING FREE ZX80/M.ACE CODING SHEETS. 


LAMO-LEM LABS 


CODE 204, BOX 2382, LA JOLLA, CA 92038 


ANN MG 
А KNW 


ASS, 


SLOT MACHINE 


PULL THE HANDLE (NEWLINE), AND WATCH THE REELS 
CLICK INTO PLACE. ASSORTED PAYOFFS. WITH FULL 


will loop between addresses 17405-17412 
until a key is depressed. The INA,(C) 
instruction will place the contents of the 
B Register onto the address lines A8-A15 
and the contents of the C Register onto 
address lines A0-A7. Therefore, by rotating 
a zero through the B Register and keeping 
the C Register set to zero, the keyboard 
can be scanned. When the data lines 
change, we know a key was depressed. 
Now we must decode the findings. 

When a key is depressed, the accumu- 
lator and the B Register are analyzed to 
determine which key was depressed. Figure 
2 shows the A and B Register contents for 
each key. 


Accumulator Contents 
30 29 27 23 


[e 
Сл 


254 
23.3 
251 
247 
239 
223 
191 


V 
G 
T 
5 

6 

У 
Н 


Register В Contents 


line 
127 | space œ M N 


UJ 


Figure 2. 


f 
d 


~ 


wh 


9.95 


МО POSTAGE. 
NO HANDLING. 
NO SALES TAX. 


Тһе program now checks each bit of 
the accumulator to determine which one 
is low. Register C is incremented once for 
each bit tested. Then each bit of Register 
B is checked to determine the one that is 
low. Register C is incremented by five for 
each bit tested. 

The contents of Register C are then 
used as an offset for the look-up table 
found at addresses 17458-17497. The look- 
up table value is placed in location 17400 
and the subroutine returns to the program 
that called it. 

It should be noted that this program 


case.’ Code could be added to look for 
the SHIFT key code. If detected, the 
program could then add an offset to 
Register C and jump back to look for 
another key to be depressed. The look-up 
table must then be expanded to include 
all the SHIFT characters. 


Conclusion 

Although the code may be difficult to 
follow at first, the program is really doing 
a lot in 97 bytes of memory. 

By the way, this program is fast! If you 
use it as a subroutine in a Basic program, 


the USR instructions, or the keyboard 
input program will decode the NEWLINE 
key that you depress after the RUN 
instruction — unless, of course, you release 
it in a matter of milliseconds. A good 
trick is to include a FOR loop of about 10 
just before the USR call instruction to 
give you enough time to release the 
NEWLINE key. 

Now that I can read the keyboard, it is 
just a small matter of time before hitting 
the ham bands. But first, maybe I had 
better functionally check the system by 
running a few quick games of Acey 


reads the total keyboard but only ‘lower- be sure enough Basic instructions precede — Ducey. a" 
17449 45 55 low 
А 17450 68 104 high 
Keyboard Scanning Program 17451 221 335 LD A.(IX--d) 
Address Decimal Octal Comments 17452 126 176 d 
17453 x X don't care 
17401 14 16 LD C,0 17454 50 062 LD 17400, A 
17402 0 0 17455 248 370 low order 
17403 6 6 LDB, 254 17457 201 311 high order 
17404 254 376 
17405 203 313 RLC B 17456 67 103 high order 
17406 0 0 17457 201 311 RET 
17407 237 355 INA, (с) 17458 1 table starts 
17408 120 170 17459 63 
17409 254 376 CP A, 31 17460 61 
17410 M 17461 40 
17411 40 50 JR Z, 17462 59 
17412 248 370 (-8) 28 compliment 17463 38 
17413 221 345 LD IX, Table addr -6(17452) 17464 56 
17414 33 41 17465 41 
17415 44 54 17466 43 
17416 68 104 17467 44 
17417 95 137 LD E,A 17468 54 
17418 0 0 МОР |For future 17469 60 
17419 0 0 МОР. | reference 17470 42 
17420 14 16 LDC,1 17471 55 
17421 1 1 17472 27 
17422 22 26 LD DO 17473 29 
17423 0 0 17474 30 
17424 62 76 LDA, 00111011 17475 31 
17425 59 73 17476 32 
17426 198 306 ADD A,000010000 17476 32 
17427 8 10 17477 33 
17428 50 62 LD(17437),A 17478 28 
17429 29 35 low 17479 37 
17430 68 104 high 17480 36 
17431 103 147 LD НА H is holder 17481 35 
17432 122 172 LDA,D 17482 34 
17433 129 201 ADDA,C 17483 33 
17434 87 127 LD D. A 17484 52 
17435 124 174 LDA.H 17485 46 
17436 203 313 BITE 17486 58 
17437 X X Don't care 17487 62 
17438 & 040 JR NZ, cont. 17488 231 
17439 242 362 -14 17489 49 
17440 88 130 LD E,B 17490 48 
17441 203 313 BIT C,2 17491 47 
17442 81 121 Test for a five 17492 45 
17443 14 016 LDC,5 17493 0 
17444 5 5 17494 155 
17445 40 050 JRZ, back 17495 50 
17446 233 351 - 17496 51 
17447 122 172 LDA D 17497 39 
17448 50 062 LD(17453),A End of Program. 


SYNC Magazine 


The TLS Function 


Rolf L. Miller 


Do not overlook the use of the TL$ function when you are 
creating programs. It is a very useful item. This function 
allows the 7Х80 user to process a string in much the same 
way that other computers READ DATA statements. 

To see how it works in this fashion, consider first the 
CODK(string) function. It will “read” and give the code of the 
first character ina string. Thus, if A$=“ABC”, CODE(AS) 
would result in 38, the code for A. 

Now add the TL$ function: LET A$=TL&(A$). Тһе TL$ 
function strips the first character from the string—A in this 
case — leaving “BC” in A$. If CODE(AS) is now reintroduced, 
it will “read” B and give its code, 39. 

Clearly, an entire string can be “read” in this way. So, for 
example, say you have a stock portfolio of five stocks, namely: 
100 shares of ABC, 200 of XYZ, 300 Q, 200 KLMN, and 100 
ZX. The following program will print the number of shares in 
100s, the stock symbol, ask for the last (current) price per 100 
shares (stock prices are quoted per share so that 5 1/4 would 
be input as 525), and, then, after all five stocks have been 
processed, print the total value of the portfolio. 


Rolf L. Miller, 492 S. Anacapa, Ventura, CA 93001. 


as 
қ Қ E e. 

ЖТ yh 

Ti Co S 


“It’s a new game called ‘Artillery’! Pretty Realistic, Huh... ?" 


July/August 1981 


10 LET У=0 
20 LET P$=“.1 АВС.2 XYZ.3 Q.2 KLMN.1 ZX.” 
30 IF CODE(P$)=27 THEN LET P=CODE(TLS§(P$))-28 
40 PRINT CHR$(CODE(P$)); 
50 LET P$=TLS$(P$) 
60 IF P$=“” THEN GOTO 130 
70 IF NOT CODE(P$)=27 THEN GOTO 40 
80 PRINT, * INPUT LAST PER 100” 
90 INPUT L —use 100 for test RUN 
100 LET V=V+(L*P) 
110 CLS 
120 GOTO 30 
130 CLS 
140 PRINT “PORTFOLIO VALUE= ”;V —test RUN should 
give 900 


In line 20 it is noted that the code for . is 27 and acts as a 
flag to control the loop routine following. 

In line 30, subtracting 28 from the code for 1, 2, 3, etc. 
results in 1, 2, 3, etc. since the code for 1 is 29, for 2 is 30, etc. 
and thus sets P at the proper value. Note here that the TL$ 
function is used to “look” one character ahead in the string 
without actually stripping the string. 

To see the value of the TL$ function here, try writing a 
program without using TL$ to accomplish the same results as 
this program and look at the length and memory difference. 

Another example of using TL$ is seen in this version of 
Mastermind. Further applications will be left to your imagina- 
tion. | 


Mastermind 


Э КЕМ COFYRIGHT 1981 BY ROLF L. 
10 LEX Х=15 

20 LET A=9999+RND (22768) 

ЗО LET A$=STRE (A) 

40 LET Вф=аф 

ЗО IF Хо THEN GOTO 190 

60 LET XzX-1 

70 LET 2-0 

80 PRINT "5 NO.GUESS ": 

90 INFUT 6% 
100 IF 6%=A% THEN GOTO 220 

110 РКІМТ (5%; 
120 IF BH$-"" THEN GOTO 170 

150 IF CODE (G$)=CODE (HRS) THEN LET 77-1 
140 LET G$-TL$t(G3$) 
150 LET Bt=TL (Bs) 
160 GOTO 120 
170 PRINT " 
180 GOTO 40 
190 FRINT 


MILLER 


"22. RIGHT ВХ (2 әр.) 


200 PRINT "YOU LOSE THE NO. WAS "A$ 
210 STOF 

220 PRINT 

250 FRINT „A$ 

240 PRINT 


20 PRINT “YOU WIN" 

Frogram Notes: 

110 displays number guessed. 
170 displays number of digits 
in proper place of sequence 


and number of turns left 
in i bh, 


11 


A Subroutine for Serial Data Output 


Trying to write machine code sub- 
routines for my ZX80 presented some 
problems. This article details the problems 
with their solutions, and shows a simple 
subroutine to output data serially by bit 
to an asynchronous peripheral. 

The first problem was to find a space in 
RAM to write my subroutine. The obvious 
space was the SPARE area shown in 
appendix П of the ZX80 Manual (See 
Figure 1). It is easy to find the start of the 
spare area by PEEKing into locations 16400 
and 16401 which point to the display file 
end "DF-END" (ZX80 Manual, appendix 
III). But the problem is that the SPARE 
area is sandwiched between two dynamic 
areas. The VARIABLES, WKG SPACE, 
and DISPLAY FILE may expand pushing 
DF-END closer to the top of stack and 
overwriting my routine. The stack itself 
may get bigger and overwrites the 
routine. 

A second problem came up when I 
tried to save the program on cassette. My 
machine code subroutine was not saved 
simply because the SAVE statement causes 
the ZX80 to save on cassette from the 
start of RAM up to E-LINE only (Figure 
1). 

A technique around these problems was 
to include my subroutine in a REMark 
statement and thus allocate a fixed area 
of RAM for it. I was able to save it on 
cassette, too. 


5. Onsy, Р.О. Box 2952 SAFAT, Kuwait, State of 


Kuwait, Arabian Gulf. 


12 


S. Onsy 


ee aaaaaaaaaamamamaħÃă 


SYS VARS 


RMBOT 
PROGRAM 

VARS 

VARIABLES 
E-LINE 

WKG SPACE 
D-FILE 

DISPLAY FILE 

DF-END 


SPARE 
SP 
STACK 


Figure 1. ZX80 Memory Map. 


I used the following procedure to input 
the subroutine: 

1. Calculate the length, in bytes, of the 
subroutine. 

2. Enter a REM statement at line 1. 
Line 1 is used to insure that the REM 


statement will always be the first one in 
the program and that it will have a fixed 
address in RAM. Using numerics helped 
counting the number of reserved bytes. 
The REM statement appeared as follows: 


0001 REM 012345678901234567890123456 
7890 etc. 


3. Enter the subroutine starting at address 
16428. 


Restrictions 

While writing the subroutine I noticed 
the following: 

1. Never use the code/data of 76 hex 
since it is an end of statement to the 
ZX80. OP code 76 hex is not used anyway 
since it is a HALT command to the Z-80 
microprocessor. 

2. Since codes 40 to 7F hex cause 
problems with the ZX80 LIST command 
if they are included in the REM statement, 
I avoided displaying the REM statement. 
This was achieved by adding dummy 
statements until it disappeared from the 
screen and then deleting the dummy state- 
ments. 


Applications 

The listed Z-80 subroutine was used to 
output data asynchronously to a serial 
printer at 300 baud. The output was taken 
from IC-11 pin 11 (Figure 2). The signal is 
at TTL level, and therefore the interface 
circuitry in the printer was bypassed (Figure 
3). The baud rate can be changed by 
simply changing the bit time loop. 


SYNC Magazine 


Figure 2. Serial O/P from IC11. 


From ZX80 ІСІ1-11 


I/P 239 Po | 
pees 1488 (typical) 


or CCITT 
Figure 3. Typical I/F circuit. 


The Basic program shown uses the above 
subroutine to LIST itself on the printer 
from the PROGRAM area in RAM. The 
program is slow and not practical to use. 
However, it demonstrates some techniques 
for the ZX80. I have included enough 
REMarks to make the program self- 
explanatory. Since the program uses a 
flow similar to the ZX80 LIST command, 
it will be practical and much faster if the 
program is rewritten in the Z-80 code 
making use of the ROM subroutines. In 
the following discussion all addresses, 
codes, and data are in hex. The registers 
mentioned are the Z-80 internal registers. 

The heart of the ZX80 LIST statement 
is a call to 04F7 which edits statement 
lines from the PROGRAM area in RAM 
into the display file. Register HL’ points 
at the statement being edited while the 
resulting statement is stored at the location 
pointed at by DF-END. The 04Е7 sub- 
routine further calls two subroutines: 


ОӨВЕ: ‘Translates statement numbers 
from binary to decimal ех- 
pressed in the ZX80. 

Changes the commands and 
operators (i.e., codes > D3) to 


their proper mnemonics. 


0684: 


July/August 1981 


The following flow chart shows how a 
printer LIST routine that uses the ROM 
subroutines may look: 


ENTRY 


Preset Z-80 registers. 


Check BREAK key. 


BREAK? 


CALL O6BF: Get 
statement number. 


Next character falls 
between 40 and 7F? 


Character >CO 


CALL 0584: Get 
mnemonics. 


CALL 0559: Store 
character. 


Translate statement from 
ZX80 code to ASCII and 


print. 
N 
P End of Program area? 
Y 
O! O3 
a-— EXIT 


NEW ENGLAND 
SOFTWARE 


7 GAMES FOR THE ZX80 
AND MICROACE ON CASSETTE 


MASTERMIND 
DOUBLEMIND 
SLOT MACHINE 
CRAPS 
TIC TAC TOE 
SUB RESCUE 
WHITE HOT NUMBER 
ALL RUN IN 1K RAM 


New England Software 
Box 691 
Hyannis, MA. 02601 


Е 
£ 6.00 Irs ass (U.0.A. 


Air Mail (England) 


YOUR BEST VALUE IN 
QUALITY SOFTWARE 


Are you in 
SYNC? 


If not, you should be. We would like any 
programs, translations of existing pro- 
grams, games or tips which you have to 
pass on to fellow Sinclair ZX-80 or Micro- 
Ace owners. Articles are much more 
lively if accompained by photos (black 
and white), diagrams, and illustrations. If 
you do not have an output printer, please 
type program listings and carefully check 
them against the listing on the screen. 
Sample runs should be included with pro- 
grams rather than just a description of 
what the program does. Articles should be 
typed, double space. Your name and 
address, with phone number should be on 
first page; all other pages should be num- 
bered. All submissions should include re- 
turn postage. Payment ranges from $15 to 
$40 per printed page. 

Please send all submissions to: 

SYNC 
39 E. Hanover Avenue 
Morris Plains, New Jersey 07950 


13 


Output Subroutine 

This is a subroutine to output one byte 
serially by setting and resetting a latch in 
the 7Х80. Тһе data is preceded by a start 
and followed by a stop bit. The subroutine 
expects the byte to be at (DF-END)+2. 
All addresses, codes, and data are in 
hex. | 


Can a computer mow your lawn? Not yet. 

But a flowchart can show you how to 
make money cutting five lawns a day. The 
flowchart is easy. Mowing the lawns is still 
hard work. 

Dr. Sylvia Charp and Marion Ball wanted 
a way to introduce basic computer concepts 
to children in grades 5 to 9 of the Philadelphia 
City Schools. So they identified some tasks 
that kids understood like mowing lawns, 
issuing paychecks and controlling traffic 
lights. They showed how computers are used 
in these tasks. 


14 


LABEL 


SPACE 


NZ,LOOP 


OPERAND 


ADR 


CHRCTR РОЗН HL SAVEHL 402C Е5 
LD H,IY-c*11) GET ADDRESS ОЕ 402D FD 6611 
LD Г.(ТҮ--10) DF-END AND 4030 FD 6E 10 
INC HL INCREMENT 4033 23 
INC HL TWICE 4034 23 
BR (HL) GET NEXT BIT 4035 СВІЕ 
POP (HL) RESTORE HL 4037 El 
DJNZ BITTEST IF NOT LAST BIT 4038 100C 
GO TEST IT 
STOPBIT ІМ A,(FE) OTHERWISE OUT 403A DB FE 
JR BITTIME A STOP BIT AND 403C 1811 
RETURN 
ENTRY LD HL,402C INITIALIZE HL 403E 21 2C ЗЕ 24 
SCF AND PREPARE FOR 4042 0609 
CCF START BIT 4044 37 
BITTEST PUSH HL SET RET ADDRESS 4045 35 
JR NC,SPACE IF ZERO SPACE 4046 3004 
MARK IN A,FE OTHERWISE MARK 4048 DB FE 


BITTIME LD D,80 START ОҒ ОМЕ ВІТ 404Е 1680 
LD E,F6 TIME LOOP 4050 IE FD 
LOOP INC D 4052 14 
JR NZ,LOOP 4053 20FD 
INC Б 4055 IC 


Computer 
ря лене 


Flowcharts - A basic concept 


They devised flowcharts. They located 
scores of photos. And they found an artistic 
high school student to illustrate these con- 
cepts with lively full-color drawings. 

They then wrote a light-hearted but infor- 
mative text to tie it all together. It talked 
about kinds of computers, what goes on 
inside the machine, the language of the 
computer and howcomputers work for us. 

They took the problem of averaging class 
grades and showed how a simple yrogram 
could be written to do this job. 


Well-qualified authors 


Marion Ball has written other books on 
computer literacy. Sylvia Charp is the director 
of educational compuuting for Philadelphia 
City Schools. They pooled their talents to 
produce this book, Be AComputer Literate. 

This easy-to-read book explains how com- 
puters are used in medicine, law enforce- 
ment, art, business, transportation and ed- 
ucation. It's interesting and understand- 
able. 


Too much demand 


The Bell System distributed 50,000 copies 
to schools throughout the U.S. but they 
couldn't meet the continuing demand. So 
Creative Computing Press now distributes 
the book. It's just $3.95 plus $1.00 shipping 
and handling. Send name and address plus 
payment or credit card number and expiration 
date to Creative Computing Press, Morris 
Plains, NJ 07950. Visa, MasterCard and 
American Express orders may also be called 
in toll-free to 800-631-8112 (in NJ 201-540- 
0445). 

Order yours today. If, after reading it, you 
do not feel that you are "computer literate,” 
return it for a full refund plus your postage 
to send it back. 


creative 
competing 


Morris Plains, NJ 07950 
Toll-free 800-631-8112 
(In NJ 201-540-0445) 


SYNC Magazine 


Program Listing 


0001 REM < CLEAR ) CLEAR (7742 ОК (МОТ REM 
М < N?-2 CLEAR *4 CLEAR 04 IF B89 


535628 


КК 


0005 КЕМ ЖЖЖЖЖЖЖЖЖЖЖЖЖ ЖЖ ЖЖ ЖЖ ЖЖ ЖЖ ЖЖ ЖЖ ЖЖ K K K K K ЖЖЖ ХХ Ж 


opio REM 
0015 КЕМ 
оого REM 
0025 REM 
0030 КЕМ 
0055 REM 
0040 REM 
0045 REM 
0050 REM 
0055 КЕМ 
OAD REM 
0063 REM 
0070 REM 
0075 REM 
HOBO REM 


END+2. THE OUTFUT ТО THE SERIAL 


INTEGRATED CIRCUIT OF THE 2Х80. 


GET ASCII CODES FROM 2Х80 CODES. 


FOR THE COMMAND/GPERATOR CODES. 


WILL ВЕ АТ TTL LEVEL АТ FIN 11 ОҒ 


THE РАОБКАМ ALSO DEMONSTRATES THE 
STRING VARIABLES АЗ à TRANSLATION TABLE TO Ж 


THIS FROGRAM LISTS ON АМ ASCIT SERIAL 
PRINTER THE PROGRAM AREA OF THE 2Х80 КАМ. 
THE REM STATEMENT 0001 CONTAINS A 280 
CODE ТО OUTFUT ONE CHARACTER ASYNCHRONOUSL Y x 
АТ 200 BAUD. THE ENTRY POINT IS АТ 
16446. THE ASCII CHARACTER SHOULD ВЕ АТ DF-X 
PRINTER 


pL 23 


USE ОР 


THE FROGRAM USES а TABLE IN THE 2Х80 ROM 
USED BY THE LIST STATEMENT TO GET MNEMONICSX 


Ж 
* 
x 


ADDRESS X 


Ж 
Ж 
Ж 
Ж 
Ж 
Ж 


Ж 


0140 REM OOOO OK ROKR RK ROKK ROKK KKK KK RK KKK KKK KK KK KEK KK 


0150 REM Ж 

0160 REM жжжжж TRANSLATION TABLE ЖЖЖЖЖ 

0170 REM Ж 

0180 LET X$-"446444444444448UZCDHFEJXYWVGI" 
0190 REM 


0200 REM A=ADDRESS OF CHARACTER TO БЕ FRINTED. 


16424 
0210 LET A=16424 


0220 КЕМ LA=LAST ADDRESS TO BE PRINTED. БЕТ TO VARS. 


O230 LET LA=PEEK (16292) +256*FEER (16293) 

0240 REM XXXX* SUBROUTINE ADDRESSES жжжжх 

O250 LET CRLFz1070 

о260 LET SFACE=1190 

0270 LET FPRINT=1240 

0280 LET XLATE=970 

Q290 REM 

ооо REM Xxxxx MAIN FROGRAM ЖЖЖЖХ 

0510 КЕМ INITIALISE LINE COUNTER 

Q320 LET LC=1 

ОЗЗО REM NEW FAGE 

0540 FOR 4-і TO 5 

0350 GO SUB CRLF 

O2Z60 NEXT J 

0370 REM STATEMENT NUMBER 

0580 LET SN=FEEK (A) Ж256+РЕЕЕ (А+1) 

0390 GO SUB SFACE 

O400 FOR Ј=1 TO 4 

0410 LET T=SN/1000 

O420 LET C=T+48 

0430 GO SUB FRINT 

0440 LET SN=(SN-TK1000) k10 

0450 NEXT 4 

0460 LET Я=А+1 

0470 REM STATEMENT 

0480 LET А=А+1 

0490 (ЕТ С=ҒЕЕК (A) 

0500 IF С=118 THEN GO TO 880 

0510 IF С>211 THEM GO TO 610 

0520 IF 05227 THEN LET C=C+20 

0530 IF C557 THEN LET C=C+7 

0540 IF C28 THEN GO SUB ХАТЕ 

оззо GO SUB PRINT 

0560 GO TO 480 

0565 КЕМ 

0570 КЕМ COMMANDS AND OPERATORS 

05/9 КЕМ 

0580 REM Fi=FLAG TO INSERT SFACE BEFORE 
AND AFTER MNEMONICS. 

0590 REM F2=FLAG TO DEFINE END OF ММЕМОМТС. 


0600 REM В =ADDRESS OF CURRENT CHARACTER 
IN MNEMONICS TABLE. 


0610 LET В=186 

0620 (ЕТ Е1=0 

0630 LET Е2=0 

0640 FOR JO ТО С- 212 

0650 LET B=B+1 

0660 IF РЕЕК(В)<128 THEN GO TO 650 
0670 NEXT J 

0680 LET B=B+1 

0690 LET С=ҒЕЕК (BR) 

0700 IF С“128 THEN GO TO 730 
0710 LET F2= 

0720 LET C=C-128 

0720 IF C227 THEN GO TO 760 
0740 GO SUB XLATE 

0750 LET Fi=2 

0760 IF Е120 THEN GO TO 790 
0765 LET D=C 


July/August 1981 


0770 
07795 
0780 
0790 
0795 
овоо 
0810 
овго 
0850 
0840 
0850 
OB60 
0870 
0880 
0890 
0900 
0910 
0920 
09:30 
0940 
0950 
0960 
0970 
0980 
0990 
1000 
1010 
1020 
1020 
1040 
1050 
1060 
1070 
1080 
1090 
1100 
1110 
1140 
1150 
1140 
1290 
1160 
1170 
1180 
11790 
1200 
1210 

1220 
1230 

1240 
1200 

1260 

1270 
1280 

1290 

1200 


NOT RE 


INITIALISED ТО 


GO SUB SFACE 

LET C=D 

LET Fi=1 

LET C=C+27k(1/F1) 

IF C232 THEN LET Fi=1 
60 SUR FRINT 

IF F2=0 THEN GO TO 680 
IF Fi-2 THEN GO TO 480 
GO SUB SPACE 

60 TO 480 


REM END OF STATEMENT 

REM 

GO SUB CRLF 

LET А=А+1 

IF БАЗА THEN GO TO 920 

STOF 

IF 162951 THEN GO TO 520 

GO TO 380 

REM 

КЕМ ЖЖЖЖЖ XLATE SUBROUTINE KKK KK 
REM 

LET Y$=X$ 

FOR J=0 TO C 

LET Y$-TL$(Y$) 

NEXT J 

LET C=CODE (Y$) 

RETURN 

REM 

REM ЖЖЖЖЖ CRLF SUBROUTINE KKK KK 
REM 

REM CC=CHARACTER COUNT 

LET CC=0 

LET LCO=LC+1 

LET С=15 

GO SUB РКІМТ 

LET C=10 

GO SUB РКІМТ 

REM DELAY FOR CARRIAGE TO SETTLE 

FOR К=1 TO 5 

NEXT Е 

RETURN 

REM 

REM ЖЖЖЖЖ SFACE SUBROUTINE KKK KK 
LET C=32 

REM 

REM ЖЖЖЖЖ PRINT SUBROUTINE 29299: 
REM 

REM C-ASCII CODE FOR CHARACTER TO BE FRINTED 
LET CC-CC-*1 

PORE РЕЕК (16400) +256xF EEK (16401) *2,C 
LET G=USR (12446) 

IF 73>CC THEN GO TO 1300 

GO SUB CRLF 

GO TO SPACE 

RETURN 


15 


How Is К Done? 


Introduction 

This article shows how a routine can 
be written and entered into a Z X80 that 
enables the user to SCROLL the display. 
In the 4K monitor there is no facility at 
all for doing other than printing to the 
last line of the display, and then, when 
the display is full, the program will stop 
unless a CLS (clear screen) command is 
used. 

The 8K monitor does have a SCROLL 
command, but it is limited in use as it 
only enables the user to scroll the whole 
display one-line-up and to print to the 
bottom line again. 

The routine in this article will only work 
under the 4K ROM. 


Objectives 

My first objective was to produce a 
routine that would simply scroll the display 
one-line-up, when called by a USR com- 
mand and allow the user to continue 
printing at the end of the display. However, 
a second objective soon appeared and 
that was to extend the routine so that 
only a predetermined part of the screen 
would be scrolled, thereby enabling the 
user to have a “title” area at the top of 
the display that would remain un-scrolled. 
The routine would require from the user 
that the number of lines to be left un- 
scrolled be specified, using a POKE 
command, before using the USR com- 
mand. 


Dr. Ian S. Logan, 24 Nurses Lane, Skellingthorpe, 
Lincoln LN6 OTT, England. This article is the 
third in a series. 


16 


Screen Scrolling 


Dr. І. 5. Logan 


The Theory 

Before writing a routine that manipulates 
the contents of the display file, we must 
have a clear understanding of the structure 
of the display file of the ZX80. Figure 1 
shows the parts of the display file as they 
would be produced by running the simple 
program: 

10 PRINT “FIRST LINE” 

20 PRINT “SECOND LINE” 
Press RUN and NEWLINE. 


-—— D-FILE 


FIRST LINE 118 


SECOND LINE 118 


— 
| 
| 
L 


Figure 1. 


21 end-of-line 
characters 


SYNC Magazine 


OLD Display File 


NEW Display File 


«--Г-ЕПЕ -&—— D-FILE 
118 118 
FIRST LINE 118 FIRST LINE 118 
»| SECONDLINE 118 SECOND LINE 118 
(11 characters) 
THIRD LINE FOURTH LINE 118 
FOURTH LINE 118 FIFTH LINE 118 DF-EA 
(reduced 
by 11) 
DF-END 
does not 
FIFTH LINE 118 5 reqane 
DF-END updating! 
Figure 2. 


Note that the lines are of varying length 
and that they all end in a “118” (Hex. 76) 
which is the end-of-line marker. 

The pointer D-FILE always points to 
the first character in the display file, which 
is always an end-of-line character. 

The pointer DF-EA points to the start 
of the “lower part of the screen,” and DF- 
END points to the twenty-fifth end-of-line 
marker. 


It is important to realize that the pointers 
DF-EA and DF-END are only given their 
final values when the execution of a 
program finishes. Before this time the 
pointers are being changed as each char- 
acter is added to the display file. Therefore 
before the “end of program” routine is 
executed the pointers DF-EA and DF- 
END both point to the last location in the 
partially completed display file. 

In a scroll routine it is necessary initially 
to collect the current value of D-FILE 
and then look through the display file 
until the point is reached that is to become 
the “new” contents of D-FILE. However, 
if certain lines are not to be scrolled, then 
these lines must be passed over, and the 
last end-of-line marker considered to be 
D-FILE. 


July/August 1981 


The length of the line to be erased is 
then found, and the scrolling is achieved 
by moving the whole of the remainder of 
the display file down in memory so that it 
overwrites the scrolled line. There then 
remain two house-keeping tasks. The value 
of DF-EA and the value of the system 
variable 16421, the line counter, need to 
be altered. DF-EA has to be reduced by 
the ‘length’ of the erased line, and the line 
counter has to be incremented (one added) 
to take into accunt that there is now one 
less line in the display file. 

Figure 2 shows the action of the scrolling 
routine that has left 2 lines and then scrolled 
once, deleting line 3. 


Loading the Routine 

The following method can be used to 
enter the routine into the ZX80. The 
routine is kept in a REM statement held 
off the screen so do not try to list it. 

Enter the following lines: 

10 REM 12345678901234567890123456 
78901234567890123456789012345678901 
2345678901234567890 

20 КЕМ *** SCROLL *** 


30 REM FIRST POKE 16427 WITH 
THE NUMBER OF LINES TO BE LEFT 
THEN USE LET K=USR(16430) 

Now push line 10 off the screen by using 
EDIT. 
The actual steps are: 

HOME 

EDIT 

RUBOUT,RUBOUT, ENTER 40 and 
NEWLINE. 

EDIT 

RUBOUT, RUBOUT, ENTER 70 and 
NEWLINE. 

EDIT 

RUBOUT, RUBOUT, ENTER 80 and 
NEWLINE. 

EDIT 

NEWLINE 

LIST 20 

and delete lines 40, 50, 60, 70 and 80. 

The actual machine code can now be 
POKED into line 10 by using a simple 
loader. 


17 


The Assembly Language Listing 


4028 

4qQOZ2B OO 

4020 OO оо 

4O2E 2а ОС 40 
4021 ED SB ОЕ 40 
дода 22 20 40 
4038 23 

4059 O1 00 00 
40230 SE 73 

ДОЗЕ ZC 
ДОЗЕ ЕВ 
4040 А? 
4041 ED 5 
404% 20 О 
4045 CF О 
4047 19 
4048 ЕВ 
4049 ВЕ 
404A 28 O4 
4040 22 

4040 QC 

404E 18 EF 
4050 За 2B 4 
4055 А, 

4054 28 06 
4056 3D 

4057 SS ӘБ 40 
доза 18 D9 
довС 79 

4050 EB 

ДОЗЕ n? 

AoSF ED 52 
4061 44 

4062 4D 

406% 2A 20 40 
4066 ЕВ 

4067 ED ЕО 
4069 ZA ОЕ 40 
4O06UC ДЕ 

4060 27 

4oó6E ED 42 
4070 22 OE 40 
407% SA 25 40 
4076 2C 

4077 32 да 40 
407A C9 


nd 


LEAVE 
NEW D-FILE 
START 


LINE END 


NEXT 


ERROR 
NO ERROR 


э COUNT 


SCROLLING 


ORG 4028 

DEFB 

DEFW 

LD HL, tD-F ILE? 
LD DE, (DF-EA) 
LD СМЕМ D-FILE),HL 
INC HL 

LD ЕС, +0000 
LD А, +79 

ІМС а 

ЕХ DE,HL 

AND А 

SBC HL, DE 

JR NC,NO ERROR 
RST 0008, "9" 
ADD HL, DE 

ЕХ DE, A. 

ЕР (HL?) 

JR Z,COUNT 

INC HL. 

INC С 

JR | NEXT 

LD A, (LEAVE) 
AND A 

JR SCROLLING 
DEC A 

LD (LEAVE) „га 
JR LINE END 


LD А.С 

ЕХ  DE,HL 

AND А 

SEC HL, DE 

LD BH 

LD C,L 

LD HL, (NEW D-FILE) 
EX DE,HL 
LDIR 

LD HL, (DF-EA) 
LD C,A 

SCF 


SBC HL, BC 
LD (DF-EA),HL 

LD А, (LINE COUNT) 
INC а 

LD (LINE COUNT), Â 
RET 


No. of lines unaltered. 
Line end address store. 
Pick up D-FILE. 

Fick up DF-EA. 

Address of scroll line. 
Enter next line. 
Initialize counter. 
Form end-of-line 
marker in A register. 
Change over registers. 
Clear carry flag. 

Find if DF-EA has 

been reached. 

Will give "А" error. 
Reform HL. 

Exchange back registers. 
Look for end of line. 
Yes. End of line found. 
No. So go to next 
character, incrementing 
counter and address. 
Collect the parameter. 
Is it zero? 

Yes. бо scroll. 

No. So pass to next line. 
Replace the parameter. 
Back to LINE END. 

Save C in A register. 
Exchange registers. 
Clear carry flag. 

Find length of rest of 
the display file and 
put it in ВС. 

Collect the line end 
address and scroll the 
display file. 

Reduce the value of 
DF-EA by the size of 
the character count 

of the scrolled line 
that was saved in A. 
Increment the value 

of the system variable 
16421- line count. 
Return to Basic. 


100 FOR 1=16427 to 16506 
110 INPUT A 

120 POKELA 

130 NEXT I 


The data for this routine is: 


0,0,0,42,12,64,237,91,14,64,34,44,64,35, 


1,0,0,62,117,60,235,167,237,82,32,2, 


207,9,25,235,190,40,4,35,12,24,239,58, 
43,64,167,40,6,61,50,43,64,24,217,121, 
235,167,237,82,68,77,42,44,64,235,237, 
176,42,14,64,79,55,237,66,34,14,64,58, 


37,64,60,50,37,64,201 


So enter lines 100 to 130 and RUN 100. 
Enter the machine code carefully. The 
checksum for the data is 6578, and this 


can be checked by adding the lines: 


18 


90 LET T=0 
110 delete 


120 LET T=T+PEEK(I) and using RUN 90 


140 PRINT T 


Now delete all the lines from 90 onwards 
and SAVE. 


Using the Scroll Routine 

The following demonstration program 
shows in a simple way how the routine 
can be used. 


With the routine stored in line 10, held 
off the screen, enter: 

40 for І- 1 TO 23 

50 PRINT "LINE ”;I 


60 NEXT I 

70 POKE 16427,2 

80 LET K=USR(16430) 
RUN 


In line 70 always specify how many lines. 
Line 80 calls the scroll routine. 


The result of the above program should 
be to produce a display in which "LINE 
3" is missing, and the remainder of the 
display has been scrolled up a line (hence 
the gap between "LINE 22" and the error 
report). 


SYNC Magazine 


ERROR А Report 

The routine does declare an error when 
an attempt is made to hold more lines 
unscrolled than actually exist in the display 
file at that particular moment. This can 
be seen in the demonstration program by 
changing line 70 to read: 

70 POKE 16427,24 
This asks the routine to scroll all the lines 
after the 24th. Clearly a confusing situation 


An Example Use of Scrolling 

The following game shows just one of 
the many uses to which the scroll routine 
can be put. In this game you will test your 
skill at driving along a road. The scroll 
routine is used to scroll the “road” and 
also to remove an “end message”; in this 
case the message is “PRESS 5,6 or 8.” 


many lines are to be left unscrolled is 
specified on each occasion that the scroll 
routine is called. 

This game program is really only a first 
try at using the scroll routine, so I would 
therefore be very interested in seeing 
programs from readers who use this routine 


so ERROR A is reported. Note carefully how the parameter of how in writing their own programs. a 
Road Game 

10 as previously prepared and held off the screen. 

20 REM STOP » Just а reminder. 

30 RAONDOMISE ; Different every run. 

40) PRINT , "жжж ROAD GAME sex" ; Title. 

эй PRINT ; Space, 

ЕЙ LET C=ø ; Cet odometer to zero. 

70 GO TO 190 ; бо past subroutine. 

ӘЙ LET SzS-RNDCcCS52-3 ; Move road a little left or right, 
90 IF 6554 THEM LET S=4 ‚ but not off the left, 

100 IF 652250 THEN LET S=20 ; nr off the right. 

110 FOR A=1 TO 5-2 ; Print "one mile" of road. 

128 PRINT "ИВ": № сн: ++ Ad , Hard verge, 

150 NEXT A : 

140 PRINT " "5 (4 өр.) ; Print four spaces for the road. 
150 FOR A=St2 TO 32 > Тһе other hard verge, 

16@ PRINT "В"; В сн: ++ A? i 

170 NEXT A , 

180 RETURN ; One mile of road printed. 

199 FOR К-і ТО 4 ; Print four miles of road 

200 LET $15 >» but fixed; rather than curved. 
210 60 SUB 110 ; Each mile. 

z2U NEXT R , 
50 FOR R=1 TO 3 ; Now Print three miles of road 
240 60 SUB 50 ‚ that does use the random function 
2590 NEXT К ; to move the road left or right. 
26@ LET Т=119+РЕЕК (1696, › +РЕЕК ‹ ; Initial car position. 

16597) ж25Е, 1 

270 LET R=T ; Сору it. 
220 POKE К, 20 ; Print the car. 

230 PRINT , Add an end of line marker. 

500 PRINT ; Space. 

510 PRINT : "PRESS 5,6 ОК 2" ; Left, right, or straight ahead. 
520 INPUT А ; Collect direction. 

20 POKE 16427,9 > Hold the title and road unscrol led. 
540 LET T=USR( 164309 ; Scroll away the blank lins. 

i50 POKE 16427, 9 + Hold the title and road unscrollsd. 
360 LET T=USRC 16430) ; Scroll away 'PRESS 5.6 OR 8: 
370 IF A=8 THEN LET R=R-CRNDCS) > Turn tO right,» but not always. 
ад 

290 ТЕ A=5 THEN LET R=R+CRNDCS3 > [urn to left, but not always. 

) 2) 

i30 POKE 16427,2 +" Hold the title unscrol led. 
400 LET T=USR( 164303 ; Scroll the road 

410 GO SUB SU ‚ Add another mile of road. 

420 IF NOT PEEKCR}I=@ THEN GO ТО > Test to see if runs off road. 
450 

420 LET C=C+1 > Increment odometer. 

440 GO TO 250 з "Survived" so drive on. 

450 PONE К, 148 > "CRASHED" 

460 PRINT , Add епа of line marker. 

470 PRINT ; Space. 

бод PRINT "ж YOU CRASHED AFTER , Тһе sign of failure, 


July/August 1981 


19 


Тһе Take-Away Game 


Pn 


to remove the last coin from the board is the /oser of the game. 


Find the Numbers 


f we add the digits of a two-digit number together, we get the sum of 5. 
Now, if we write this two-digit number down, reverse it, and subtract the 


smaller number from the larger number, we find that the difference is 27. 
Can you tell us what these two numbers are? 


N 


АА \ 


The Farmer and His Four Sons 


et’s start off with a game you might care to program for your ZX80 
computer. Lay out five rows of five coins each on the table. Each player, in 
turn, may remove one or more coins from any row or column of coins. 
However, there cannot be a gap between any of the coins. The coins 
; removed must be contiguous within the row ог column. To illustrate, 
Ж j suppose the first player removes coins number 3 and 4 from the top row of 

NÉS coins. His opponent could not then remove coins 1, 2 and 5 from this row 
because there would be a gap between coins 2 and 5. This player could, 
however, remove coins 1 and 2, or 5 from this row. The person who is forced 


х Ден 


ООО ОО 
O O ОО 
O OO O 

O O ООО 

O O O O OO 


ОО 


Тмо-Юг-Опе 


еге we have two checker puzzles. The first one is а 
checker problem and is pictured at the left. White 
has the move and should win in seven moves. Can 
you solve it? The second problem is straight forward 
enough. How many squares are there on a checker- 
board? If your answer is 64, sit down and give 
someone else a chance. (From Merlin’s Puzzler 3 by 
Charles Barry Townsend, published by Hammond, 
Inc.) 


An Easy Creditor 


gentleman was in temporary need of money. A friend 
lent him sixty dollars, telling him to repay it in such 
sums as might suit his convenience. Shortly after- 
wards he made a payment on account. His second 
payment was half as much as the first; his third 
three-quarters as much, his fourth one-quarter as 
much and his fifth two-fifths as much. It was then 
found, on striking a balance, that he still owed two 
dollars. 

What was the amount of the first payment? 

(From Puzzles Old & New by Professor Hoffmann 
circa 1890) 


nce upon a time (now where have I heard that before) a farmer 
owned a square field which had four apple trees growing on it. The 
trees were neatly spaced in a row as shown in the drawing at the right. 
The farmer had four sons that he wanted to divide the field among. 
His problem was that each son had to have an identically shaped 
piece of the field. Also, each piece had to be the same size in area. 


Finally, each piece of the field had to have one apple tree on it. If you 
had been the farmer, how would you have divided up the field so that 


each of the sons would receive his fair share? 


readers of SYNC, send it along. If Merlin uses it, he will send you a copy of 


hat’s it for this issue. I hope you have enjoyed the problems brought by 
Merlin. If you have a favorite puzzle that you would like to share with the 


Merlin’s Puzzler, a great book filled with the best in puzzles and games. 
Until next time, keep puzzling! 


Your editor, = 2 
Charles Barry Townsend Ж 4 © wa 


20 


Answers on page 27. 


SYNC Magazine 


S 


Fred D’lgnazio and Stan Gilliam have 
created a delightful picture book adven- 
ture that explains how a computer works 
toa child. Katie “falls” into the imaginary 
land of Cybernia inside her Daddy's home 
computer. Her journey parallels the path 
of a simple command through the stages 
of processing in a computer, thus 
explaining the fundamentals of computer 
operation to 4 to 10 year olds. Supple- 
mental explanatory information on com- 
puters, bytes, hardware and software is 
contained in the front and back end 


*; new friends 


|, ог your child... 


Katie and the Computer 


Thrill with your chidren as they join the 
Flower Bytes on a bobsled race to the 
CPU. Share Katie’s excitement as she 
encounters the multi-legged and mean 
Bug who lassoes her plane and spins her 
into a terrifying loop. Laugh at the 
madcap race she takes with the Flower 
Painters by bus to the CRT. 


“Towards a higher goal, the book 
teaches the rewards of absorbing the 
carefully-written word and anticipating 
the next page with enthusiasm...” 

The Leader 


papers. 
“Children might not suspect at first 
there’s a method to all this madness—a 
lesson about how computers work. It 

does its job мей.” 
The Charlotte Observer 


*...the book is both entertaining and 
educational.” 
Infosystems 


The book has received wide acclaim 
and rave reviews. A few comments are: 

"Lively cartoon characters guide read- 
ers through the inner chamber of the 
computer." 


School Library Journal 


“...ап imaginative and beautifully con- 
ceived children's story that introduces 
two characters—the Colonel and the 
Bug—who already seem to have been 
classic children's story book characters 
for generations." 

The Chapel Hill Newspaper 


Written by Fred D'Ignazio and illustrat- 
ed in full color by Stan Gilliam. 42 pages, 
casebound, $6.95. (12A) 

A t-shirt with the Program Bug is 
available in a deep purple design on a 
beige shirt. Adult size S, M, L, XL. 
Children's size S, M, L. $5.00. 


To order, send a check for books plus $2.00 shipping and handling per order to Creative Computing, Р.О. Box 789-M, Morristown, NJ 07960. NJ residents add 5% 
sales tax. Visa, MasterCard, and American Express orders are welcomed. For faster service, call in your bank card order toll free to 800-631-8112 (in NJ call 


201-540-0445). Or use the handy order form bound into this magazine. 


INVENTIVE PROGRAMS 


FOR THE ZX80 4K ROM/1K RAM 


Games, subroutines, and teaching aids in 4 K BASIC 
and MACHINE CODE. All listings include statement/ 
subroutine logic and 8К ROM/16K RAM appendix. 


PRICE: $1.00 per program listing 
(minimum order 10, plus $2.50 S & H) 


PARTIAL LIST * (4K/1K) 


* FLIP-A-COIN * TEST PATTERN 


* 1 KEY BANDIT * CASSINDEX 
* TURRET GUNNER * FOIL FENCING 


ж 2X80. BASIC TEST * BANG! FOR 1 


* BLACKJACK * EASTER DATE 


* FIBONACCI SEQUENCE * STATE CAPITALS TEST 


* COORD GRAPHICS 


demonstration picture. 


ж MACHINE CODE DISPLAY 
* BARRAGE * GUILLOTINE 
ж ACEY-DUCEY II * KEYBOARD GRAPHICS 
* LINE RENUMBER ж 81 BOXES 


TO ORDER. 


Specify programs wanted and enclose payment. 
yet succeeded. 


ZETA SOFTWARE 
P.O. BOX 3522 
GREENVILLE, S.C. 29608 


onlyo 


* Complete list sent with your order, or send SASE 
for FREE list and order blank. 


IHGA Иза 


ZX80-4K ROM 


quality software... 


1K Space Intruders $20 ? 


Written in machine code 

to give fast moving 
‘Flicker Free' graphics. 

A superb achievement. 
Supplied as a listing only. 


16K High Resolution $20% 
(192x192) graphic pictures 


Never before achieved on the ZX80. 
Create your own artwork. 
as а listing (25.99 extra if cassette 
required) with full screen 


Supplied 


9K Nightmare Park $15 > 


A good example of a BASIC 
program using MACRONICS 
'Amazing Active Display' 
The park of DEATH - can 
you get through this 


nightmare. No human as 


Confronted by all sorts of 'Happenings' 
you'll be taken to your wits end. 


Supplied on cassette 


Send International cheque or money order {о :- 
MACRONICS, 26 Spiers Close,Knowle, Solihull 
West Midlands B93 9ES, United Kingdom 
other MACRONICS software available 
from IMAGE COMPUTER PRODUCTS 
in the United States 


Subroutine 


10 DIM BC2S) 


20 БОК 1=0 TO 23 
хо LET BCI) =0 

40 NEXT I 

So FOR 1=0 TO 23 
60 FRINT I 

70 INPUT BCL) 


Во IF BCI) =0 
“О IF ірпо THEN GLO 
100 NEXT I 


Erase lines 10-100 and 


THEN STOr 


Setting Up Bar Charts 


Jon Passler 


A bar chart is one of the most commonly 
used methods of graphically presenting 
data for quick interpretation. Such charts 
work nicely within the constraints of the 
ZX80 and MicroAce. Beside making for 
a good display, they provide an excellent 
way of storing data. 

The program listed here works with 1K 
to chart two years of monthly checking 
account balances with vertical bars. The 
graph is set up for a range of $0 to $1500, 
but can be modified for other ranges with 


use 50 


TO 1 instead of RUN hereafter. 


Bar Chart Program 

100 КЕМ GO TO 1 (Leave cursar on line 

110 FRINT 100 when Saving 

120 PRINT reminder not to КОМ.) 

150 FRINT "X100 AVE DAILY BALANCE" (5 өр.) 
140 PRINT "-----(3 sp. and 17 SHIFT G)” 

190 РКІМТ 

160 FUR, іе TO © 

170 LET Еж (ТУЗ) k1O-TRKLO/S 

180 IF K=O AND 15-9 THEN РКІМТ —I3s"-"; 

170 IF Кер AND I;-10 THEN FRINT " ПЕ (1 
200) IF КО THEM PRIN] "=": (2 өр.) 
210 FOR J=0 TO 23 

S260 ТЕ ВЈ) =0 THEN GO TO 290 

2S0 LET DsBHBGDO--IX100 

240 IF Dé-225 THEN PRINT " "g (1 sp.) 

2300 IF D2—26 AND Dz22 THEM FRINT CHRS (7); 

260 IF D524 THEN РКІМТ CHRS$;130)3; 

2/0 NEXT J 

200 PRINT 

270 NEXT I 

Ооо PRINT ~” 1980 КӨӘНІРТ E) 191” 4f. 
эзо STOP 

зо КЕМ Б(16) 

22 


а few changes and some trial-and-error 
experimentation. Of course, any other sort 
of data such as monthly rainfall or average 
temperatures, miles-per-gallon, electricity 
use, or frequency distributions (histograms) 
can be plotted. 

Because of memory limitations the array 
storing the data is created and filled in a 
routine that is later erased (lines 10-100). 
All elements of the array contain either 
data or zeroes, and line 320 is used to 
show the user which element of the array 
should be filled next. To add a monthly 
figure enter 330 LET В(16)= ХХХХ, then 
GO TO 330 and N/L, and finally erase 
line 330 and update line 320 to REM 
B(17). 

After entering the program, you can 
enter the following data to see how it 
works: 1012, 796, 931, 1236, 1252, 1088, 
786, 1132, 1194, 908, 1113, 896, 913, 849, 
553, 429. "n 


Jon Passler, 344 Cabot St., Beverly, MA 01915. 


4, and = sp.) 


SYNC Magazine 


Bisection Iteration 
Square Root Program 


10 PRINT "SQUARE ROOT OF Xx" 

го FRINT "ENTER X "s (3 spaces) 
aD INPUT X 

40 PFRINT X 

52 LET Цео 

60 LET H=162 

70 LET Тен) 72 

GO LET R-X/T 

90 IF kef THEN GOTO 160 

100 IF H-L < 2 THEN GOTO ТО 160 
110 IF Е X T THEN GOTO 140 

i20 LET Бет 

150 GOTO 79 

140 LET HsT 

1520 GOTO 79 

160 PRINT "ROOT 15 "sl 62 spaces) 
170 PRINT 

180 STOP 


NOW AVAILABLE 


| sion 


oard 


Keyboard vith complete parts and plans $55.00 


Wired keyboard, complete with plans $75.00 


Mail for information: 


L.J.H. Enterprises 
P.O. Box 6273, Orange, CA 92667 


For information or Visa or MasterCard orders call 
(714) 772-1595. Shipping charge for U.S.—$5.00. 


July/August 1981 


Mike Goins 


This program operates by means of 
bisection iteration, which is basically just 
a variation of the old high-low game. The 
size limitation of the integer basic (уап- 
able size) limits the maximum root to 181. 

Besides the mathematical value, this 
Square root program is handy for use as a 
subroutine to represent the distance 
between two points (using the Pythagor- 
ean theorem) in some game programs in 
which one might try to guess the location 
of an object and when in error to find out 
by how great a margin. : 


Mike Goins, P.O. Box 3341, Bristol, IN 37620. 


SUPER INVASION 


ON YOUR ZX80! 


SYNC magazine says Super Invasion is the 
<.. best action game we have seen for the ZX 80." 


DOUBLE BREAKOUT 


DOUBLE BREAKOUT challenges you to get through two barricades, 
using two ball angles. With seven levels of play, DOUBLE BREAKOUT 


is hard to beat. You'll be amazed at the superb 
graphics in this 1K game. $14. 95 


SUPER ZX80 INVASION 


SUPER ZX80 INVASION is a flicker free, moving graphics game with 


three levels of play. SUPER INVASION challenges your skill as you 
shift your craft left and right and fire lasers at the invading 


space ships. Added bonus — each cassette 
contains a more sophisticated 2K version. $ 14. 95 


23 


Multi-Dimensional Arrays for (һе ZX80 


Jamie O’Connell 


How many times have you sat down to 
convert a program for the ZX80, only to 
find that the first line was 10 DIM 
A(10,10)? Chances are that you gave up 
and turned the page. The next time you 
do not have to turn the page because it is 
possible to simulate dimensioned arrays 
on the Sinclair through the use of a simple 
algorithm. 

Many versions of Basic define a two- 
dimensional matrix by the command DIM 
A(X,Y); where the X is the row subscript, 
and Y, the column. Any location on the 
matrix can be accessed by specifying 
values for X and Y. For example, LET 
A(3,4)=9 assigns the value 9 to the element 
located at row 3, column 4. 

On the ZX80, we define a one-dimen- 
sional/vector array containing as many 
elements as we need and then use a simple 
formula to locate a given element. For 
example, if we want to initiate a 10 by 10 
matrix, the instruction DIM A(99) sets up 
100 locations and the formula A(X+ Y*10) 
—9 assigns to the element at (X,Y) the 
value 9. In order to save space, the first 
element in the array simulates A(0,0) and 
the last, A(9,9). If we take the first element 
to be A(1,1) (as it is in most Basics), then 
we would use the general formula A((x- 
1)+(y-1)*X). These formulae result in 
column-order storage: all of column 1 is 
stored before 2. To simulate row-order 
storage, use the formula A((y-1)+(x-1)*Y) 
as in Figure 1. 


In similar fashion, arrays of any number 
of dimensions can be accessed. The 
element A(X,Y,Z.,...) is located at A((x-1) 


Z X80 Basic 


10 DIM A(59) 
20 LET Х-3 
30 LET У=1 
40 LET 7-2 


Tiv-D*X-iz-D*X*Y -G.OTX*Y*Z4-, А 
simple comparison shows how the ZX80 
can simulate three-dimensional Basic: 


3-dimensional Basic 


10 DIM A(3.4,5) 
20 LET Х-3 
30 LET Ү-і 
40 LET 7-2 


50 LET A((X-1)+(Y¥-1)*3+(Z-1)*3*4)=9 50 LET A(X,Y,Z)—9 


ZX80 Simulated Simulated Simulated 
Actual Column-order Column-order — Row-order 
Location Location Location Location 


A(L  L=x+y*3 


A(0) A(0,0) А(1,1) 
А(1) А(1,0) А(2,1) 
А(2) А(2,0) A(3,1) 
A(3) А(0,1) А(1,2) 
А(4) A(1.1) А(2,2) 
А(5) А(2,1) А(3,2) 
А(6) А(0,2) А(1,3) 
А(7) А(1,2) A(2,3) 
A(8) A(2,2) A(3,3) 
A(9) A(0,3) A(1,4) 
A(10) A(1,3) A(2,4) 
A(11) A(2,3) A(3,4) 


L=(x-1)+(y-1)*3 L-(y-1) + (x-1)*4 


A(3,4) 


Figure 1. Simulated Locations for a 3 by 4 Array 


Jamie O'Connell, Apt. 17 Cricket Brook, Dover, 
NH 03820. 


24 


The best way to illustrate the use of 
dimensioned arrays is by a demonstration 
program. The one offered below is fun 
because the movement of the ship is 
essentially random. You can never know 
where it is until you blow it up or actually 
have it captured. Note that in a 10 by 10 
matrix the array location is the same as 
the simulated location: A(37) is equivalent 
to A(3,7). This allows direct input of the 
coordinates desired. The display routine 
illustrates a fairly standard procedure for 
the printing of a matrix. 


Capture 

Capture is similar in some respects to 
many other matrix manipulation games; 
but, instead of trying to hit the enemy, 
you must surround and immobilize him. 
If you do succeed in hitting his location, 
you lose the game. 

You have a total of fifteen mines which 
you use to block the enemy's progress. 
For a capture, his progress must be 
blocked in every direction. The display 
will show you where he was on the 
previous move. You can always place a 
mine at this previous location, as he has 
to move one space on each turn. 

Lines 10-50 set up the enemy’s initial 
location. Lines 80-195 output the display 
which shows: the matrix, the previous 
enemy location, the number of mines left, 
and the location of the mines as you place 
them. Lines 210-60 decide the enemy's 
new location, test for capture, and check 
the remaining number of mines. Lines 
370-430 input your mine placement coor- 
dinates and test for a hit on the enemy. 


SYNC Magazine 


| 


EMT WT 


To vary the number of mines, change 
line 60. Line 370 was keyed in using the 
following space saving technique: 370 
INPUT (SHIFT 5) PRINT “ (SHIFT 8) 
ROW-COLUMN"'. If you fail to use this, 


the program will print error code 4 when 
run—every byte counts! When entering 
the coordinates at line 370, enter them 
both before hitting NEWLINE. Happy 
hunting! "s 


Capture Program Listing 


10 RANDOMIZE 

20 DIM A(99) 

38 LET X=RND(1@)-1 
АЙ LET Ү-ВМр(10)-1 
50 LET А(Ү-Х%10)-148 
60 FOR M--16 TO 2 

76 PRINT 


8g PRINT "1 WAS LAST AT,. a" 


96 PRINT 


100 PRINT " 9123456789" 


110 FOR І-й TO 9 
120 PRINT Т; 
138 FOR J= TO 9 


140 PRINT CHRS(A(J+I*19)); 


150 NEXT J 

160 PRINT 

176 NEXT I 

18% PRINT 

190 PRINT "MINES-";-M 
195 PRINT 

200 LET A(Y4X*10)-g 
210 FOR Т=1 TO 64 

220 LET I-RND(3)-2 
230 LET I=I+X 


240 IF I 9 OR I Ø THEN GO ТО 220 


256 LET J-RND(3)-2 
260 LET J-J4Y 


276 IF J 9 OR J Ø THEN GO TO 250 
288 IF І-Х AND J-Y THEN GO TO 256 
290 IF NOT А(9+1*10)=26 THEN GO TO 339 


300 NEXT T 


310 PRINT "OOPS-CAPTURED" 


320 STOP 

338 LET X-I 

ЗАЙ LET Y-J 

350 LET A(Y«4X*19)-148 


366 IF M=@ THEN GO TO 440 
376 PRINT " INPUT ROW-COLUMN" 


380 INPUT R 


398 IF A(R)-148 THEN GO TO 460 


416 CLS 
420 LET A(R)=2¢ 
438 NEXT M 


448 PRINT "OUT OF MINES" 


450 STOP 


468 PRINT "YOU BLEW ME UP" 


July/August 1981 


Capture Sample Run 


I WAS LAST AT... 


0123456789 


МО oN ОМА > бо го н О 


MINES=16 
INPUT ROW-COLUMN 


17 


I WAS LAST AT... 


0123456789 


O 

T ж 
2 ж * 
3 х х ж ж 
4 B -* 
5 хх ж * 
6 

Т 

8 

9 

MINES=3 


INPUT ROW-COLUMN 
45 
I WAS LAST АТ... 


01234567 
0 
1 ж 
A ж ж 
3 хх * X 
4 х Щщ х 
5 ххх 
6 
f 
9 
9 


MINES=2 
OOPS-CAPTURED 


8 9 


25 


TRS and LET AS=AS-+BS оп the 7Х80 


Harry Doakes 


String handling on the ZX80 is reason- 
ably good. The 4K Integer Basic lets the 
user print, input, and compare strings, 
and do specialized routines that will 
transform numbers into strings or charac- 
ters. 

There are also some large holes in its 
string handling abilities though such as 
limited string truncation and no conca- 
tenation. It is not hard to figure out why: 
Integer Basic takes up less than 3600 bytes 
of space, since the character generator, 
about 500 bytes long, is also in the 4K 
ROM. The only command for changing 
the size of a string is TL$ (which stands 
for Truncate (shorten) from the Left of 
the String). PRINT TLS(“FRED”) produces 
“RED”; TLS chops off the leftmost char- 
acter of the string in parentheses whether 
it is a literal string (like “FRED”) or a 
variable (A$, for example). With TL$ you 
can trim as much as you like from a 
string—but only one byte at a time, and 
only from the left side. 

Sinclair’s Integer Basic has no string 
concatenation commands at all. In other 
words, there is nothing like LET A$=A$+ 
В$. You cannot lengthen a string. 

Other small Basics—for example, Radio 
Shack’s Level 1—allow fewer string vari- 
ables and only INPUT and PRINT com- 
mands. The ZX80 looks good by compar- 
ison, but comparison cannot fill those string- 
handling holes. 

This program can. 

Enter the program in Figure 1. Line 10 
should contain 52 zeroes. 


10 REM 00000000000000000000000 
00000000000000000000000000000 

20 FOR А=1 TO 52 

30 PRINT A;" "; 

40 INPUT B 

50 POKE 16426+А,В 

60 PRINT В, 

70 МЕХТ А 

80 INPUT A 

90 IF A=O THEN STOP 

100 INPUT B 

110 POKE 16426+A,B 

120 PRINT As" ";В, 

130 GO TO 80 


Figure 1. 


Harry Doakes, P.O. Box 10860, Chicago, IL 
60610. 


26 


Run the program and enter the following 
numbers in order. The numbers in paren- 
theses are just entry numbers. Do not key 
them in. 


(1) 175 (2) 235 (3) 30 (4 10 
(5) 197 (6) 225 (7) 57 (8) 235 
(9) 249 (10) 235 (11) 227 (12) 43 
(13) 43 (14) 43 (15) 40 (16) 9 

(17) 227 (18) 209 (19) 213 (20) 227 
(21) 35 (22) 3 (23) 3 (24) 24 
(25) 21 (26) 60 (27) 237 (28) 185 
(29) 35 (30) 235 (31) 33 (32) 0 

(33) О (34) 35 (35 12 (36) 32 
(37) 252 (38) 4 (39) 32 (40) 249 
(41) 227 (42) 193 (43) 213 (44) 227 
(45) 35 (46) 35 (47) 237 (48) 176 
(49) 235 (50) 227 (51) 249 (52) 201 


When you have keyed in the 52nd value, 
stop and proofread the contents of your 
screen very carefully. 

If you find a mistake, type the entry 
number, hit NEWLINE, then enter the 
correct value. The new version will appear 
at the end of the list of numbers. When 
you have corrected all mistakes, enter 0. 

The program listing should now look 
something like Figure 2. Delete lines 20 
through 130, and you are ready to key in 
your Own program. 

You now have two new string functions. 
The first will truncate a string from the 
right side; a TRS, if it existed, would do 
the same thing. To perform the equivalent 
of 

LET G$=TRS(G$) 
you write: 

LET G$=G$ 

RANDOMISE USR(16428) 

After the routine is complete, a PRINT 
G$ would show that the final character is 
gone. 


The second function is even more useful; 
it is the equivalent of 

LET L$=L$+M$ 
The appropriate program lines are: 

LET L$=L$ 

LET M$=M$ 

RANDOMISE USR(16427) 

At the end of the routine, M$ no longer 
exists, and L$ contains both strings. 

Each function will work with any string 
variable, A$-Z$. 

A few caveats: 

You must perform the LET commands 
immediately before the USR line. LET 
creates a new entry at the end of the list 
of variables in RAM. By performing those 
LETS, you put the strings you are working 
on at the end of the variable list so the 
USR routine knows just where to go to 
find them. 

You can substitute LET, PRINT, 
IF...THEN, and most other commands 
for RANDOMISE. Remember, though, if 


10 REM FOR 2m? OR Т FOR CONT 
ПИЈЕ FOR =FFFC#E? THEN =7mm</W Р 
ОКЕ M7 FOR 5 7£4 LOAD "4 CONTIN 
UE =? THEN =77 POKE ЖЕОК = CONTI 
NUE ? 


Figure 2. 


you create a new variable with LET, you 
will have to LET AS—AS etc. again before 
performing any more of these string func- 
tions. 

Do not try to ТК$ a string with nothing 
inside. You can do it if, for example, 
05=“ "—рш not if Q$—*". И CODE 
(Q$)=1, do not use the TRS routine. 

These routines will not work with 
literals— only string variables. You must 
put a string into a variable before you can 
perform these operations on it. 


SYNC Magazine 


1 


E 


If you want to use line 10 for your 
program, you can renumber the REM 
line using the EDIT function. It will work 
without change if it is still the first line of 
the program; if not, you will have to find 
its new location to call the routines with 
USR. The routines should never begin 
beyond 16639, or you will have to alter 
the machine language program. 

Figure 3 lists the routine in assembly 
language. The procedure is relatively 
straightforward. Each routine loads HL 
with the E-LINE value (which points to 
the end of the variable list); finds the end 
of the variable it wants to work on; shifts 
the variable list down, one byte at a time, 
until it reaches the end of the list; then 
loads the new value of E-LINE into the 
proper location. 

Parts of the routine may seem more 
complicated than necessary. The extra 
code is used to avoid instructions using 
values between 64 and 127 decimal (40h- 
7Fh). These values cause screen distortion 
and quickly crash the system if the ZX80 
tries to display them as characters in a 
string or program line. A program that 
cannot be safely listed is too impractical 
for general use, so this one avoids those 
values. The routine begins, for example, 
not with LD HL, (400A), but with a longer 
instruction sequence that avoids the unlist- 
able values. 

At the beginning of the routine, certain 
things are taken for granted: BC=0, the 
Z flag is reset, and H=40h. The first two 
are always true when a routine is called 
with a USR command. The third is true 
for any routine between USR(16384) and 
USR(16639), since the ZX80 simply loads 
HL with the starting point and does a JP 
(HL). 

Finally, notice that the end of the routine 
HL=SP. Thus, PRINT USR(16427) will 
not only add two strings together, but will 
also tell you where the top of available 
memory is. PRINT USR(16427)-PEEK 
(16400)-256*PEEK(16401) will return the 
amount free memory remaining—but be 
sure that you have the strings in place to 
be worked on, or you will scramble your 
variables and you may crash the sys- 
tem. 2" 


decimal hex assembler 
112 AF XOR А 
ЖЫ ЕВ ЕХ DE, HL 
20, 19 1ЕОА LD Е, OAh 
197 C5 PUSH BC 
225 E1 POP HL 
57 59 ADD HL, SP 
cog EB EX DE, HL 
249 F9 LD SP, НІ, 
255 ЕВ ЕХ DE, HL 
227 E3 EX (SP), HL 
43 2B DEC HL 
43 2B DEC HL 
43 2B DEC HL 
40, 9 2809 JR 2, O9h 
227 ЕЗ EX (SP), HL 
209 D1 POP DE 
215 D5 PUSH DE 
22T E3 EX (SP), HL 
55 22 INC HL 
2 05 INC BC 
5 05 INC BC 
24, 21 1815 JR 15h 
60 56 INC А 
237, 185  EDB9 CPDR 
25 25 INC HL 
299 ЕВ EX DE, HL 
25, 0,0 210000 LD HL, 0000 
25 25 INC HL 
12 OC INC C 
ја. 258 20FC JR №, FCh 
4 04 INC В 
22, 249 20F9 JR NZ, F9h 
бел Ез ЕХ (SP), HL 
193 C1 POP BC 
215 D5 PUSH DE 
227 Е5 ЕХ (SP), HL 
25 22 INC HL 
25 25 INC HL 
237, 176  EDBO LDIR 
255 EB EX DE, HL 
227 ЕЗ ЕХ (5Р), НІ 
249 FQ LD SP, НГ 
201 C9 RET 

Figure 3. 


А=О, 221 
D=40h 
EzOAh 
НІ-О 


HL=SP 

DE-SP, НІ-400АҺ 

SP=400Ah 

HL=SP 

HL=(400Ah), (SP)=SP 

(HL)=80h 

D -O01h 

(HL)=character 

jump to $+$ 

DE= HL 
(DE)=character 


(HL)=Oth 
BC=0002h 


jump to finish 
$+$: A=Oth 
BC=displacement 
22. 
(DE)z01h 

HL=0 

НТ=-ВС 


BC=HL=displacement 
HL=DE 
(HL)=character 
finish: shift until 
BC=0, DEZE-LINE 


HL=SP, E-LINE=E-LINE 
sP=SP 


Duzzie answers 


Find the Numbers: 41 and 14 


Two-for-One: (A) White to move and win: 26- 


22, 18-25, 21-17, 14-21, 19-16, 12-26, 27-31. (B) 
There are 204 squares in a checkerboard. Some 
are single squares, some are made up of 4 
squares, 9 squares, and so on. 


July/August 1981 


The Farmer and His Four Sons: 


An Easy Creditor: The amount of the first 
payment was $20. To ascertain this amount, let 
x = the first payment. Then according to the 
conditions of the puzzle: 
X 3x X 2x 
xt + 4 + 4 777% + 2 = 60 
Multiplying by 20, the least common multiple 
of the various denominators, 
20x + 10x + 15x + 5x + 8x +40 = 1200 
58x = 1200 - 40 = 1160 
x = 20 


27 


АДА % % b Z » “> А Р 
527 t #2 ” Б Ж SO 2% Ly 


6 
Г 2 2 a= A 
2 a: 2222 
ЈА ОДУ 2 : A 


eS 


рс9с905 
(5596000) 
0009 
050 


0009 
DOO 
SOG 


2... 
erate’ 


OS 
(5290505 
о. 


0.9.9 0.99 © "s" ааа: 
SOOO OO 
IIIA AS, OK, 


$$ 
Ж e estere 
ЖОС eon 
ee: s 
оо о Wi o. 752505 


im 
PX 


5 IT 
^ % 
9 


СК 
НК 
И КА 


, 
пла ee 
елле 


S50 
ХУ 
DOR ^o] 


о СЧ 
DOW ‘+ 
DO 


XX 
> 
(060000) 

500050000 
хо 

4949000 

SO 
tete 
ох, 


m 
зуы) 
me 
mm 


NIST, 


s . e 

/ 3 D ыру - / A ? 

22 У ч Ro 

p 2 Ж, У 4 ? • 4 2 È sete A 4 О 
6 ве»: ` 6; : - | сэй. . 


A 5 
wae КИМ У отту urter! 
МУ ТЕ 


COOL THE SOLAR < 
У TRUE HEART’S LOVE! 2 WIND, CRASH / you 
м , Р Ep-- MARRIED < ЕЕ-- 7 
y 22 OE Бага ЖАМ ОТ ON МЕ? ЖИ 


SEE YOU AGAIN 7 


ETHING CAM | 
ТНЕ yg y NEEDED 


EVERYTHING 4 
WAS ALL READY’ 


STOW IT, 
CURSOR?’ WE 
WERE SUPPOSED 
TO GET MARRIED! 

REMEMBER 2/ 


... ГР BOUGHT ANEW WEVDVING- 
GOWN AI GIMBLES/... A TUX FOR 
YOL (NOT MOMS 
FLOWERS/ CAT ЕК! Ж 
HONEYMOON SUITE 


3 


ON EXZEMAX...! 


AWAY OUT OF 
THIS JOINT / 


ҸӘ 


4 “> 


т? M// 
КОКУ? 
ps 


+ 


"p 


pe 
SUIVEZ" 


HELP, 


A E 
7 


"M 


4 


~ 


"f 


MALL 
27 


> ЕЦ 
QUILILY 2 A 


fo 


CLIRSO, 
HAS HUNG HIMSFE: 


4 


у ре "i S 
в 
Ж 2 


CLL Li Ahhh SA 
“алас А 


АУА ҚОСА 


402772772 


. | %, МА 


4 
4," 


^» 


4 > 
"y 
за 


S 
g 


4 
NW 
SS 
ANNNNNNNNNNNNNNNNNNNNNNNNA, 1. uw t 


ob 


* ^» 
279%, 


22 


У 


D 
ho 


Р 


"ERE 
| 


Jab oa Му NY 
ААА DT 
t 


kek: 
WR_A i iw 


СХА 
OQ 


£ 


2 ; 


\ 


| 


P ИГ АМ 
DE FROBLUM 


WANN 
© ~ ЕК 


===, 2 
ЖЖ” Ф 
2 


ЗАДА, N 
У фед 2; - 4 ў 
“А 


хо 
RES 
> % ,” ; 
НИ ГА ? A 4 
е, > 
2, ; . 
eu Q 4 50 y 
7, OO" 4, ..... Be Q 9 Ж 
Le ett 50% SKS QUOD x > • 4 
RAO I % ^ % я 
У р SSS % ЖҰ 
РОД (fs: 66 


S 
- 
NNNNNNNN 


Pd 
“ 


QUICK-BUT PRAMATIC— 


READOUT BY SYNK..- 


Aw SO4FOLLOWING А 


~ 


`` 


, Би KNOW... 


МАСЕ ---т”-.-................м.р.., 


МЕ 
50 
Е 


SYNK 2 


NEW SHOES 


те Tn ERE a ao 


WAIT 
v | 


7-%.- 


-- WOW. 
A MINAS: 


2 


"— VLIH -- 
| yEAH/1 G0! 

GEEZ ому TURNED му NOW! Yur 

l AET HELP! 


BACK FOR A SECOND, ТО CLEAN 
МУ VISCS, АМИ WHEN | TURNED 
AKO "^ THERE HE WAS-- 
TRUSSEP LI? LIKE АМ AKCTLIEAN 
TURKEY’... HANGING THERE 
LIKE A MARTIAN HAM 7227 


IT MUST HAVE BEEN THE 
SHOCK OF INCARCERATION / 
CRASH WAS A FREE SOUL , 
USED TO THE FREEDOM 
ОЕ SPACE,ONE WITH THE 
о THE WINVS OF 
SPACE BLOWING THROUGH 
HIS RECENTLY-WASHEP 
HAR! THE PULSE OF 
MALEUNZTIONING ROCKETS 
RAN THROLIGH HIS BLOOD, 
HIS HEART KEEPING : 
TIME WITH THE BLE 
ОЕ STAE-FIRE., HIS 
FEET WITH THE SOUND 
ОЕ THE FOOTFALLS OF 
PURSUING CEEVHOES ! 


ES A 
AND Now, ITS . 
COME TO TENS...) 


WELL, сом TUST [—- ее 


Cos! COMPUTER- X 
LASER ÉANUSANS /! MORE... !!! 


Тһе ZX80 Makes the Grade 


Lawrence Auer 


Introduction 

It is not a toy! Even with only 1K bytes 
of storage, the ZX80 can be an invaluable 
aid to the teacher in the calculation and 
evaluation of grades. In this article we 
present two programs running on the 1K 
Basic machine. The first determines the 
test scores and keeps track of which 
question caused the class the greatest 
difficulty. The second finds the class 
distribution of grades, enabling the teacher 
to scale the grades. While with more 
memory the two programs can be easily 
combined, presentation of the separate 
codes is made for those, like me, who 
want to do something while they wait for 
the 16K memory to arrive. 

These programs have been used to 
handle the bi-weekly exams of twenty 
questions given to the 95 students in my 
introductory astronomy class. While, in 
principle, the same sort of computations 
could be accomplished at the university 
main frame computer, there is no compar- 
ison between that and a comfortable chair 
in front of the TV апа 7Х80. Further, 
because of the way the programs are set 
up, the data can be entered piecemeal, 
with more being added at your con- 
venience. Finally, the tape storage system 
makes it a trivial task to keep the results 
for all the tests together. You can mount 
the cartridge and “instantly” see how the 
class did on any exam. 


Program 1: Test Scoring 

Using the ZX80 to add the scores on 
questions is an obvious and useful applica- 
tion. The ZX80 can be even more useful, 
however, because it can also keep track 
of which questions are being missed. After 
all the tests are graded, the teacher has a 
measure of which concepts were the 
hardest for the students. Knowing the 


Lawrence Auer. 1301 Park Hills Ave.. State College. 
PA 16801. 


July/August 1981 


question-by-question scoring, the teacher 
can see exactly which topics need review. 

Before using the first program, edit lines 
10 and 11. N is the number of questions 
on the test (20 or fewer; more may cause 
memory overflow). P is the default number 
of points per question. This number is 
used for the default when no number is 
explicitly entered in answer to the prompt 
at line 136. The reason for having a default 
P is that most answers are right (we hope!) 
and it is needless to have to enter numbers 
when just a single NEWLINE will do. 

Having defined N and P appropriately, 
we can now enter the data. In response to 
the prompt “О”, where О is the number 
of the question whose score is being 
requested, reply with the value earned. 
As described above, NEWLINE by itself 
will give the default value, P. Any other 
number is simply typed in the normal 
manner. The characters “К” and “Е” are 
special and are interpreted as follows: 1) 
“К” stops (1.е., "kills") the program at this 
point. You can resume grading at exactly 
this point at a later time simply by using a 
CONTINUE command. More on this 
below. 2) “Е” means the last score entered 
was in "error." The score is erased, and 
you are asked to correct its value. 

After the scores on each question have 
been entered, the student's total is given. 
At this time you can get a plot of the 
relative number of points lost per question 
by typing "P" in answer to the prompt. 
The length of the bar is proportional to 
how many fewer points were earned by 
correct answers to this question than the 
one that earned the most points. Note 
that the shortest bar is the question the 
students did best on. The numeric value 
of the plotted quantity is listed at the end 
of the bar. After looking at the plot, you 
can either kill the program with "K" or go 
back to enter another exam by typing 
NEWLINE. 

After stopping the program by entering 
“К” at any time, it may be SAVEd. АП 
the relevant information is stored. The 
program and data may be LOADed, and 
you will start at the place where you 
stopped simply by executing 
CONTINUE. 


Program 2: Grade Distribution 

The overall performance of the class is 
determined by entering the test grades 
into Program 2. Grades are assumed to 
be in the range 0 to 100. A different range 
is easily accommodated by modification 
of the scaling used in line 225. Instead of 
5, use another number which maps your 
input into the range (0,20). After a grade 
is entered, a plot of the number of students 
receiving a grade in each indicated interval 
is made. The first number in a row is the 
grade interval being plotted. The length 
of the bar labeled with the value G in the 
first column is proportional to the number 
of people who scored in the range, G to 
G +4; e.g., the bar labeled 75 contains all 
who scored 75 to 79. The second column 
contains the number who scored in this 
range; the bar length is proportional to 
this figure. The third is the cumulative 
distribution, i.e., how many were in this 
grade range or lower. The cumulative 
distribution is particularly important 
because it indicates the relative merit of a 
given absolute grade. The last value in 
this column is always just the number of 
test grades entered so far. 

As in Program 1, the letter "E" entered 
instead of a grade deletes the grade just 
entered, i.e., it erases the error. If you 
type the letter "K", the program will stop. 
CONTINUE will start you again. SAVE 
preserves all data as well as the program, 
so you do not have to enter the grades 
again if something prevents you from 
finishing in one session. 


Programming Suggestions of General 
Applicability 

Several programming techniques used 
in these codes will be useful in other 
Z X80 programs. 

When you have to enter the grades for 
95*20— 1900 answers, most of which are 
for full credit, you can get very tired of 
typing “5” then NEWLINE. It is much 
more efficient simply to type NEWLINE 
(NL in prompts) and let the machine make 
the default. Unfortunately, if you are 
INPUTing into a numeric field, NEWLINE 
by itself is ignored; thus, you have to use 
a string variable for INPUT. In this case, 
NEWLINE by itself sets the string to be 
the null string, “”. The price paid is the 


31 


need to convert any non-null string to а 
numeric value. For example, one has to 
set G=15 when the input is the string 
“15”, i.e., characters “1” and “5”. The 
requisite code is in lines 148-151 of Program 
1. Line 152 takes care of the default for 
null strings. Note the use of the operator 
“ ”, which permits the code to work 
even if A$ is initially null. 

It is human (rather than machine!) to 
want to use mnemonic notation to enter 
signals for action. That is, when you want 
something erased, it is more natural to 
type “E” than to enter the value 101. 
When the input is being made into strings, 
it is no problem to check whether the 
string is the symbolic signal. This is the 
technique used in Program 1, line 265. In 
Program 2 the input is numeric, however. 
In order to use the letters “K” and “E” as 
symbolic signals there, we have to be a 
little more tricky. What we do in lines 3 
and 4 of Program 2 is to define the variables 
Е and К, giving them appropriate numerical 
values. The text typed in response to an 
INPUT statement is evaluated before being 
stored into the destination. Thus, typing 
E in response to the INPUT statement in 
line 200 is equivalent to entering the 
number 101. Typing the letter K there 
sets G=K=-1 and this value of С triggers 
the STOP command in line 201. As each 
of these variables can be set to any 
appropriate "impossible" test scores, it is 
no problem to make modifications if 
grades 100 are allowed. Finally, if you 
prefer, more dramatic and memorable 
variable names like KILL or ERASE can 
be used. 


The CONTINUE Command 

Of all the pieces of hidden gold in the 
ZX80, the most valuable is the command 
CONTINUE. When you leave the program 
execution mode either voluntarily because 
of a STOP statement in your program or 
involuntarily because of an error (like 
trying to write too much on the screen), 
the place you were when you stopped is 
remembered. While in immediate mode, 
you can do what you want, including 
resetting variables and even editing the 
program. The CONTINUE statement will 
start you again at the line following the 
one where you stopped. Thus, in these 
programs you can kill (i.e., “К”) whenever 
you want, then SAVE the file on tape. 
The LOAD operation brings in the file 
with the program, all the data, and even 
the information on where you stopped. 
CONTINE following the LOAD acts just 
as if there had been no tape storage in 
between. That is, SAVE followed by LOAD 
completely re-establishes the environment 
as it was before the SAVE operation. The 
only thing to remember if you are going 
to use the STOP-CONTINUE trick is to 
make sure that the statement following 
the STOP produces a recognizable cue. 
If you just have the sequence, 100 STOP, 
110 INPUT X, when you restart with 
CONTINUE you will have a nice blank 


Program 1: Test Scoring 


screen and the cursor waiting for input 
with no hint as to what input is wanted. 
To avoid this problem in Program 1, for 
example, line 139 jumps back to the input 
prompt, so you can tell what is expected 
when you restart. 

One of the problems in having only 1K 
of memory is that peculiar errors can 
occur when you are OUTPUTing. The 
characters to be written on the screen 
occupy the same memory as your program. 
You can, therefore, be running quite nicely, 
entering question scores, and then have 
trouble when you try the plot, because 
you do not have enough memory for the 
output. The choices made for the scaling 
of the bar lengths in these programs work 
well for my exams with 20 questions and 
95 students, but there may be something 
unusual about your distributions. If you 
do have trouble, do not panic! Simply 
change the scaling; reduce the 15 in line 
226 of Program 1 and/or the 20 in line 
120 of Program 2. None of the data will 
be lost as long as you use CONTINUE to 
restart. 

More memory will permit these programs 
to be significantly improved. Programs 1 
and 2 could then be combined so that all 
you would ever enter would be the question 
scores. Also, one could add a subroutine 
which would give the test grade above 
which a specified fraction of the class 
scored. Finally, with 16K you should be 
able to store the names with the grades 
and thus have your “mark book" on tape. 
In any case, I hope that you find these 
programs as useful as I have even in their 
limited form. 


10 LET N - 20 144 LET 5(1) = S(I) - G 

11 LET P = 5 145 СОТО 135 

20 DIM $ (м) 148 LET G = 0 

25 LET T 3 0 149 LET G = 10*G + СОРЕ(А5) - 28 
100 CLS 150 LET A$ = TL$(A$) 
105 PRINT "SCORES?" 151 IF А$ > "" THEN GOTO 149 
110 LET T = T + 1 152 IF G < 0 THEN LET С = P 
115 LET В = 9999 153 PRINT С 
116 LET 0 = 0 155 LET Z = Z + С 
120 LET Z = 0 160 LET S(I) = 5(1) + G 
130 FOR I = 1 TO м 165 IF S(I) < R THEN LET В = 5(1) 
135 PRINT "0";7; 166 IF S(I) > 0 THEN LET Q = S(I) 
136 INPUT А? 170 NEXT I 
137 IF NOT A$-"K" THEN GOTO 140 171 LET R = Q- В 

138 STOP 175 PRINT "P TO PLOT', 

139 GOTO 135 200 PRINT "GRADE",Z 
140 IF NOT AS="E" THEN GOTO 148 205 INPUT A$ 

141 CLS 210 ІР NOT A$ = "р" THEN GOTO 100 
142 LET I = I - 1 215 CLS 
143 LET 2 = 2-6 216 PRINT "REL ERRORS" 


32 


SYNC Magazine 


220 


216 
220 
221 
225 
230 
235 
240 
245 


FOR I = 1 TON 

ТР I < 10 THEN PRINT " ". 
PRINT Is" "; 

LET Z = 15*(Q - S(I))/R 
IF Z = 0 THEN GOTO 233 
FOR J = 1 TO 2 

PRINT CHR$(128); 

NEXT J 

PRINT "Ш";0-5(І) 

NEXT I 

PRINT "K TO KILL" 

INPUT A$ 

IF A$ - "K" THEN STOP 
GOTO 100 


Program 2: Grade Distribution 


REM GRADE HISTOGRAM 


LET K = -1 

LET E - 101 

DIM C(20) 

LET A = 0 

LET N = 0 

LFT $ = 1 

LET G = 0 

FOR I = 0 TO 20 
LET G = G + C(I) 
LET L = 20*C(I)/S 


IP I < 2 THEN PRINT " 8: 
PRINT 5*I 


IF C(I) < 10 AND I < 20 THEN PRINT 


PRINT C(I);"B";6; 

IF L = 0 THEN GOTO 150 
FOR J = 1 TOL 

PRINT CHRS(128) 

NEXT J 

PRINT "Д" 

NEXT I 


IF N > 0 THEN PRINT "AV-";A/N; 


REM K=KILL(STOP), E=ERRCR 


PRINT " GIVE GRADE, К OR E" 


INPUT G 

IF а > К THEN GOTO 205 

STOP 

SOTO 100 

IF С < 5 THEN GOTO 215 

LET D = -1 

LET G = 

GOTO 220 

LET D = 

LET 0 

LET N 

LET A = 
G 
8 
C 


Q 


* D 

+ D*G 

5 

C(G) * D 

5 THEN LET 5 = 


| 
Ql р» 23 a = 


yun 


LET 
LET 
IF 

CLS 
GOTO 100 


July/August 1981 


с (6) 


Blank Cassettes 


The quality of cassette tape used to 
save and load programs is an important 
factor in getting the programs to run. 
Tape quality for computers is measured 
differently from quality for audio tape. 
The tape must be capable of sending to 
the computer the electronic signals of 
the program without transmitting extra- 
neous noises that could interfere with the 
ability of the computer to load the tape. 

Our blank cassettes are tested and 
recommended for computer use. C-10 
cassette, 5 min. per side, blank label on 
each side in a Norelco hard plastic box. 
[0010] $1.25 each. 


Head Cleaner 


After hours of use, the read/write head in 
a cassette recorder will pick up minute 
particles of tape oxide. This dirt will hardly 
be noticable in dictation or music. But it is 
very noticable in computer use. One dropped 
bit in 16,000, and the program won't toad. 

Help keep your recorder in top shape 
with our non-abrasive head cleaner. It consists 
of 18 inches of stiff cleansing fabric-in a 
standard cassette sheii. One 10-second pass 
every 40 hours of use will keep your heads 
as good as new. [0011] $2.00. Send pay- 
ment plus $1.00 Shipping per order to: 


Peripherals Plus 


39 East Hanover Avenue 
Morris Plains, М.) 07950 


MUSIC! for 4K ROM, 1K or more RAM. 2 
octaves, 127 note length, any tempo. 
Songs repeat. Random sounds also. Cas- 
sette and insts. $6.95 pp. $10. outside 
U.S. Wm Don Maples, 688 Moore St., 
Lakewood, CO 80215. 


>» < тұтты» тұқ» тұты» тұта» TØ 
ое 996 C. 4 oC. 


Find 7Х-80 
Owners 


Advertise in SYNC, the magazine ex- 
clusively dedicated to the Sinclair ZX-80 
and The MicroAce. Call or write for de- 
tails and a rate card. Let SYNC readers 
know who you are. 


SYNC 
39 E. Hanover Ave. 
Morris Plains, New Jersey 07950 


33 


Multiplication 
Three-in-a-Row 


Austin R. Brown, Jr. 


“Multiplication Three-in-a Row” is based 
on the program “Multiplication Bingo,” 
by Jean Wilson, Special Education teacher 
at Leadville High School, Leadville, 
Colorado. She was seeking a way to 
motivate students who were having diffi- 
culty learning to multiply and found that 
completing five in a row on a Bingo board 
helped supply the motivation. An array 5 
by 5 is too big for the ІК ZX80, but 3 by 3 
will fit. 

The game proceeds as follows. You 
select a square on the board. You are 
then given a multiplication problem to 
solve. If you solve it within two tries, an 
“Х” goes in the square. If you fail, an “О” 
goes in the square. If you get three X’s in 
a row before the board is filled, you win. 
See Sample Run 1. 

The program can be used to build skills 
in mental arithmetic, pencil and paper 
arithmetic, or calculator arithmetic. It can 
generate other ranges of problems by 
changing lines 120-130. For example, use 
RND(19) rather than RND(9) to generate 
factors into the teens. 

This is not a tic-tac-toe game. The 
number or location of 0’s does not matter, 
as long as you can get three in a row by 
the time the board is filled. 


Programming Notes 

The program is built upon the array 
U(N), N=1,...9, where М represents опе 
of the squares on the board. If the square 
has not yet been used (the number of the 
square still shows in the display), U(N)=0. 
If the player has successfully solved a 
problem at that square, “X” shows in the 
display, and U(N)=1. If the player has 
failed to solve a problem at that square, 
“0” shows in the display, and U(N)=2. 


Austin R. Brown, Jr., 407 Peery Parkway, Golden, 
CO 80401. 


34 


Use of the array helps the program 
logic in several ways, as shown in Listing 
1. First, we can generate and update the 
display without the need for nine different 
string variables and the repetitious logic 
they require (lines 740-890). Second, we 
can easily check for an already occupied 
square,, since U(N) will no longer be zero 
(line 110). Third, we can also check for 
three-in-a-row, since we have success if, 
and only if, all three U's, and hence their 
product, are equal to one (lines 230-380). 
Fourth, we can easily tell when the game 
is over. As long as there is at least one 
unoccupied square, its U is zero (lines 
300-320). Fifth, we record a right or wrong 
answer simply by changing the current U 
(lines 190 and 510). 


Tic-Tac-Toe 

The program can easily be adapted to 
a tic-tac-toe game either for two players 
or for one player against the computer. 
Success for “О” is tested as well as success 
for ^X" in lines 230-280, except that the 
product must be eight. 

Listing 2 shows the program modified 
for a two-person game, with the computer 
simply keeping track of the action. Sample 
Run 2 shows a game. Modifying the 
program to play computer against human 
is left as an exercise for the reader. For 
example, a simple strategy of random 
moves by the computer could be imple- 
mented by the following changes: 


74 IF J=2 THEN GO TO 500 
500 LET N=RND(9) 
510 IF NOT U(N)=0 THEN GO TO 500 
520 GO TO 120 


This strategy can be bewildering to the 
human encountering it for the first time. 


Notes: 

REMarks should not be entered into 
the ZX80. They are included strictly to 
show the program logic. "n 


Three-in-a-Row 


5 REM Multiplication 3-in-a-row 
6 REM A.R.Brown,Jr. 6/1/81 
T REM Initialize 
10 RANDOMIZE 
20 DIM U(9) 
30 FOR Т=1 TO 9 
ЦО LET U(I)z0 
50 NEXT I 
60 GO SUB 700 
75 REM Pick square 
80 PRINT "WHICH SQUARE?" 
90 INPUT N 
100 GO SUB 700 
110 IF М<1 OR М>9 OR NOT U(N)=0 
THEN GO TO 80 
115 REM Generate problem 
120 LET A=RND(9) 
130 LET В-ЕМр(9) 
140 PRINT "SQUARE ";N 
160 PRINT "WHAT IS ";A;"*";p;"? 


170 INPUT C 

175 REM Check for correct answer 
180 IF NOT C=A*B THEN GO TO 500 
185 REM Right answer 

190 LET U(N)=1 

200 GO SUB 700 

210 PRINT "RIGHT" 

220 PRINT 

225 REM Check for 3 іп а row 
230 FOR K=1 TO 3 

240 IF U(K)*U(K+3) *U(K+6)=1 THE 
N GO TO 900 

250 IF U(3*K-2) *U(3*K- 1) *U(3*K) 
=1 THEN GO TO 900 

260 NEXT K 

270 IF U(1)*U(5)*U(9)s1 THEN GO 
TO 900 

280 IF U(3)*U(5)*U(7)s1! THEN GO 
TO 900 

295 REM Check for end of game 
300 FOR Is! TO 9 

310 IF 0(І)-0 THEN GO TO 80 

320 NEXT I 

355 REM Losing end 

360 PRINT "SORRY, YOU LOSE" 

370 GO TO 999 

495 REM Check error 

500 IF F»0 THEN GO TO 600 

505 REM 2nd time, answer & move 
510 LET U(N)s2 

520 GO SUB 700 

530 PRINT A;"*";pB;"z";A'*B 

540 GO TO 300 

595 REM 15% time, try again 

600 LET Е=-1 

610 PRINT "WRONG," 

620 GO TO 160 

695 REM Output tableau 

Ров CLS 

110 LET Fs] 

720 PRINT "MULTIPLY 3-IN-A-ROW" 
730 PRINT 

740 PRINT "и; 

T50 FOR 121 TO 9 

760 LET A$zSTR$(I) 

770 IF Џ(1)=1 THEN LET А%-"Х" 
780 IF Џ(1)=2 THEN LET A$="0" 
T90 PRINT A$; 

800 IF NOT 1=3%(1/3) THEN PRINT 
"М"; (Shift Я; 1 time) 

810 IF І-3 OR І-6 THEN GO SUB 8 


820 NEXT I 
830 PRINT 
840 PRINT 
850 RETURN 
860 PRINT 


870 PRINT ННН" 


(Shift А; 11 times) 


880 PRINT " u- 

890 RETURN 

895 REM Winning end 

900 PRINT "-- HOORAY, YOU WIN - 


Listing 1. 


SYNC Magazine 


Sample Run 1 


MULTIPLY 3-IN-A-ROW 


WHICH SQUARE? 


SQUARE 1 
WHAT IS 9*8? 


We gave T2 for the answer 


MULTIPLY 3-IN-A-ROW 


WHICH SQUARE? 


SQUARE 5 
WHAT IS 6*9? 
WRONG, 

WHAT IS 6*9? 


We gave first 69, then 5H 
for the answer 


MULTIPLY 3-IN-A-ROW 


WHICH SQUARE? 


SQUARE 9 
WHAT IS 7*1? 
WRONG, 

WHAT IS 7*4? 


We gave first 21, then 14 
for the answer 
MULTIPLY 3-IN-A-ROW 


July/August 1981 


Tic-Tac-Toe 


Я о л 


10 
20 
30 
40 
50 
60 
65 
69 
70 
72 


74 


80 
90 
100 
110 


REM Tic-Tac-Toe 

REM A.R.Brown,Jr. 6/6/81 
REM Initialize 

RANDOMIZE 

DIM U(9) 

FOR I=1 TO 9 

LET U(I)=0 

NEXT I 

GO SUB 700 

LET 4-0 

REM Pick square 

LET Ј=Ј-(Ј/2)%241 

ТЕ 4-1 THEN PRINT "X MOVES 


IF 4-2 THEN PRINT "0 MOVES 


PRINT "WHICH SQUARE?" 

INPUT N 

GO SUB 700 

IF М<1 OR М>9 OR NOT U(N)=0 


THEN GO TO 80 


120 
130 
225 
230 
239 
240 
0 

245 
*К) 
250 
0 

260 
265 
270 
0 

215 
280 
0 

295 
300 
310 
320 
360 
370 
695 
700 
710 
720 
730 
740 
750 
760 
770 
780 
790 
800 
п || 
810 
60 

820 
830 
840 
850 
860 
870 
880 
890 
895 
900 
910 


LET U(N)=J 

GO SUB 700 

REM Check for 3 in a row 
FOR К=1 TO 3 

LET I=U(K) *U(K+3) #U(K+6) 

IF I=1 OR I=8 THEN GO TO 90 


LET І-0/(3%К-2)%0(3%К-1)%0(3 
IF I=1 OR I=8 THEN GO TO 90 


NEXT K 
LET 1=0(1)%0(5)*0(9) 
IF I=1 OR I=8 THEN GO TO 90 


LET I=U(3) #U(5) *U(7) 
IF I=1 OR I=8 THEN GO TO 90 


REM Check for end of game 
FOR I=1 TO 9 

IF U(I)=0 THEN GO TO 70 
NEXT I 

PRINT" - TI E -" 

GO TO 999 

REM Output Tableau 

CLS 

LET Е-1 

PRINT "TIC-TAC-TOE" 

PRINT 

PRINT T п; 

FOR I=1 TO 9 

LET A$=STR$(I) 

IF U(I)=1 THEN LET A$-"x" 
IF U(I)z2 THEN LET A$="0" 
PRINT A$; 

IF NOT І-3%(І/3) THEN PRINT 
ms (Shift А; 1 time» 


, 
IF I=3 OR І-6 THEN GO SUB 8 


NEXT I 

PRINT 

PRINT 

RETURN 

PRINT 

СОВЫ ШЕБЕР 
PRINT " 5: 

RETURN 

REM Winning Ends 

IF І-1 THEN PRINT "X WINS " 
IF І-8 THEN PRINT "0 WINS " 


Listing 2. 


Sample Run 2 


ТТС-ТАС-ТОЕ 


Х МОУЕ5, 
WHICH SQUARE? 


X chooses 5. 


TIC-TAC-TOE 


О MOVES, 
WHICH SQUARE? 


O chooses 8. 


TIC-TAC-TOE 


X MOVES, 
WHICH SQUARE? 


X chooses 7. 


TIC-TAC-TOE 


О MOVES, 
WHICH SQUARE? 


O chooses 3. 


35 


А murder has been committed and the 
perpetrator has threatened to strike again! 
It is up to you to uncover the two pieces 
of evidence which will identify the murderer 
before he can carry out his threat. 

The game consists of searching the 4 
rooms in the building where the crime 
occurred for the incriminating weapon 
and fingerprints. Your initial location is 
randomly selected as are the locations of 
the gun and the prints. The amount of 
time allocated to you ranges from 6 to 30 
minutes. To remain in your current position 
or to move in either a clockwise or counter 
clockwise direction requires from 1 to 5 
minutes. A diagonal move can take from 
2 to 9 minutes. 

To search for one piece of evidence 
requires from 1 to 5 minutes; to search 
for both requires from 2 to 9 minutes. If 
your allotted time drops below 6 minutes 
one of your associates may search a room 
for you and declare it “clean” and therefore 
you do not have to search it yourself, 
although you already may have done so. 

If you run out of time, the locations of 
the fingerprints and the gun are displayed. 
If you locate the evidence, the amount of 
time remaining is printed. 

The program is loaded in three sections. 
First, an array of 72 print characters is set 
up. This array contains the floor plan 
display. 


DIM А(71) 
FOR I = 0 TO 71 


1000 
1010 
1020 
1030 
1040 
1050 
1060 
1070 


PRINT І + 1, 
INPUT K 

LET A(I) = K 
PRINT ACT) 
NEXT I 


Drew Nisbet. 6 Moffatt Crt.. Toronto, Ont.. Canada. 
М9УДЕІ. 


36 


Run this portion of the program апа 
input the 72 character codes listed below. 
If you make an error in entering the values, 


Ж Drew Nisbet 


you can either rerun the routine or correct 
individual entries with a LET statement 
(e.g., LET A(O) = 135). 


135,131,131,131,181,131,131,1381,131,131,131,134 


IF (1/12) * 12 = I THEN CLS 


0, 0, O, 31, 0,130 
0,133, 3, 0, 3,132 
0, 0, 0, 0, 0,130 
0, 0, 0, 32, 0,180 
0,133, 3, 8, 3,132 


After the first portion has been run, 
delete lines 1010 to 1070 inclusive and 
enter the following lines: 


170 LET K = 0 

180 FOR I = 1 TO 6 
190 FOR J = 1 TO 12 
200 PRINT (CHRS(AC(K)); 
210 LET K = K + 1 

220 NEXT J 

230 PRINT 

240 NEXT I 

250 STOP 


SYNC Magazine 


Key СО ТО 170 and NEWLINE and 
check the display. If it requires correction 
use a LET statement as above. If the 
display is functioning properly, it would 
be a good idea to save the partial program 
at this point. 

Now enter the main body of the 
program: 


100 RANDOMISE 

110 LET G = RND(4) 

120 LET P = RND(4) 

130 LET R = RND(4) 

140 LET M = RND(25) + 5 
150 LET GF = 0 

160 LET PF = 0 


Delete line 1000 and save the program. 
To execute, key GO TO 100 rather than 
RUN as the latter will clear the print 
codes stored in array “A”. This program 
could easily be altered in order to create 
other “Search and Find” games. By chang- 
ing the names of the articles to be searched 


LOCATION OF GUN 
LOCATION OF PRINTS 
STARTING ROOM 
AMOUNT OF TIME 

GUN FOUND SWITCH 
PRINTS FOUND SWITCH 


250 PRINT "ROOM-";R,"TIME-";M 


260 ТЕТ Q = RND(5) 
270 PRINT “SEARCH?” 
280 INPUT 1$ 


TIME FOR CIRCULAR MOVE 


290 IF 1$ = “№ THEN GO TO 470 


800 PRINT “1-GUN” 
802 PRINT “2-PRINTS” 
804 PRINT “3-BOTH” 
310 INPUT Е 

320 LETM =M- 9 


330 IF F = 3 THEN LET M=M- G 


340 IF M < O THEN GO TO 600 
850 IF Е = 2 THEN GO TO 430 
380 IF NOT G = R THEN GO TO 420 


390 LET GF = -1 
400 PRINT “GUN FOUND” 


420 IF F = 1 THEN GO TO 460 
430 IF NOT P = R THEN GO TO 460 


440 LET РЕ = -1 
450 PRINT “PRINTS FOUND” 


CHECK FOR GUN 


CHECK FOR PRINTS 


460 IF GF AND PF THEN GO TO 700 


470 LET T = RND(4) 


480 IF M < 6 AND NOT (T = G OR T = P OR T = R) THEN PRINT 


T;” CLEAN” 
490 PRINT “ROOM?” 
500 INPUT 5 


510 IF 5 < 1 OR S > 4 THEN GO TO 500 


520 CLS 
530 LETM=M- 9 


540 IF ABS(S - R) = 2 THEN LETM=M-G 


550 IF M < 0 THEN GO TO 600 


560 LET R = S 

570 GO TO 170 

600 PRINT “OUT OF TIME” 
610 PRINT “G:”;G,”P:”;P 
620 STOP 

700 PRINT “ТІМЕ-”;М 


To run, key GOTO 100. Do not use RUN. 


July/August 1981 


for and by setting up an appropriate display 
for the top of the screen this program 
could be used as a basis for a "treasure 
hunt," "spy" or similar game where it is 
necessary to locate something that is 
hidden. 


Sample Run 


ROOM=4 TIME=24 
SEARCH? 

CY? = NZL) 
i-GUN 

2-PRINTS 

3-BOTH 

Се = NZL) 

GUN FOUND 

ROOM? 


( 71" - МИ 


ROOM=2 TIME 5 
SEARCH? 
(ју: = 
i~GUN 
2-PRINTS 
3—BOTH 
(0787 = NZL) 
i CLEAN 
Коом? 

(0557 = NZL) 
OUT GF TIME 
6:4 


МИЦ.) 


Piu 


ROOM=2 
SEARCH? 
(^Y? = NZL) 
i -GUN 
2-FRINTS 
5-БОТН 


TIME=16 


f аста 


( = NL 
GUM FOUND 
FRINT&S FOUND 
ТТМЕ=8 


37 


A Parallel Interface for the 
7Х-80/МісгоАсе Computer 


Alger Salt 


Introduction 

Almost everyone who owns a computer will ask or be 
asked, “What sort of practical things can it do?” One of the 
most obvious practical applications is controlling external 
devices; however, few microprocessors or CPUs are designed 
to do this directly. 

Most manufacturers of microprocessors offer devices called 
peripheral controllers which are integrated circuits designed 
to be compatible with their particular CPU. These controllers 
greatly simplify the task of interfacing external peripheral 
devices such as disk drives, terminals, and printers. Fortunately, 
the engineers at Sinclair Research Limited chose to design 
their microcomputer around the Z-80 CPU which is well- 
supported by several excellent peripheral controllers. One of 
these, the Z-80 PIO can be used in constructing a simple 
parallel interface for the ZX80/MicroAce computers. 


Overview of the Z-80 PIO 

The Z-80 PIO is a 40 pin integrated circuit designed to 
serve as a simple direct, TTL compatible interface between 
the Z-80 CPU and peripheral devices employing parallel data 
transfer. (See Figure 1.) Communication between the PIO 
and the CPU is accomplished by connecting the PIO data 
lines directly to the CPU data bus. The PIO is a two-port 
device. This means it can send and/or receive two sets of 8- 
bit parallel data. Control lines on the PIO select one of the 
two ports (B/A SEL), enable the PIO (CE), and allow the PIO 
to differentiate control words from data words (C/D SEL). 
Three other control lines (M1, IORO, RD) insure proper 
timing sequences during CPU I/O operations. The bars over 
the signal names indicate that they are active low. 

Each port has two control lines used to establish handshaking 
between the PIO and the peripheral device. These two control 
lines (RDY and STB) are sometimes, though not always, 
necessary to synchronize data transfer. In other words, one of 
these control lines, the RDY line, may be activated to tell a 
device which is sending data to the PIO, “Do not send data 
now. Гат not ready... O.K., now I am ready. Send data.” The 
device may respond by activating the STB line, “O.K., here is 
the data. Get it now so I can do something else.” By using the 
handshake lines, communication is established between the 
PIO and the peripheral device resulting in an orderly, efficient 
transfer of data. 


Alger Salt, East Carolina University, Chemistry Department, Greenville. 
NC 27834. 


38 


The PIO contains a number of internal registers used to 
control its operation. The most important is the 2-bit mode 
control register which can be programmed to select one of 
several operating modes on port A or port B. 

The PIO may be operated in one of four modes, designated 
mode 0 through 3. Mode 0 is the output mode; all eight lines 
on the designated port are output to a device. In mode 1, the 
input mode, all lines on the port are input from a device. 
Mode 2 is the bidirectional mode and is restricted to port A. 
In this mode the handshake lines of port B along with the port 
A handshake lines are used to control the flow of data in both 


BUS k 8 I/0 
PORT A 


сво С Z-80 PIO 


LINES TORQ 


INTERRUPT IEI 1/0 
CONTROL 
LINES ТЕО РОВТ В 


Figure 1. Functional Diagram of 7-80 PIO. 


directions on port A. Mode 3, the control mode, is a hybrid of 
the input mode and the output mode; any line of the specified 
port can be designated as input or output. The control mode 
differs from the bidirectional mode in that once a line is 
designated as input or output, it stays in that condition and 
reprogramming is necessary to alter the direction of data 
transfer on that line. The handshake lines are not used in 
mode 3. A more detailed explanation of the Z-80 PIO operating 
modes can be found in references 2, 6 and 7 at the end of this 
article. This discussion is restricted to the control mode 
(mode 3). Other control registers internal to the PIO are used 
to store interrupt vector addresses, a distinguishing feature of 
the Z-80 PIO. 


SYNC Magazine 


Let us now see how to construct and program a parallel 
interface for the ZX80/MicroAce computer, using this Z-80 
PIO under non-interrupt, non-handshake control. 


Construction of the Parallel Interface 

Figure 2 shows a schematic diagram of the parallel interface. 
Port B is used for input to read the states of eight toggle 
switches (S1-S8) while port A is configured for output to drive 
eight light emitting diodes (D1-D8). Inverters are used to 
buffer the output port. The maximum output current capability 
of the PIO port data lines is about 1.5 milliamperes, not 
enough to drive an LED but enough to drive one TTL input 
or about four low power Schottky (LS) TTL inputs. The 
inverted system clock, ®, is available at pin #6B on the back 
of the computer board. This signal is inverted again before 
being presented to the PIO. The handshake lines, STB and 
RDY, on each port are not connected. They are not needed 
because operating mode 3 will be selected. Since this application 
does not require interrupts, the IEI (Interrupt Enable In) line 
is tied high and the IEO (Interrupt Enable Out) is not con- 
nected. 

Signals on the edge contacts of the computer board can be 
brought out through a cable using a modified 50-pin edge 
connector with 0.1 inch spacing between contacts (i.e., 3M 
part #3439-1000). The connector must be modified because it 
is closed ended and the computer requires an open ended 
version. The modification can be done with a sharp knife or a 
small saw. 

The parallel interface circuit should be constructed on 
some sort of plug-in circuit board for easy inspection and 
modification. A high quality plug board such as Vector’s 
4677-2DP works well since it provides an etched power and 
ground bus. Etched pads for mounting dual-inline-plug (DIP) 
integrated circuits are also provided. All ICs should be socketed. 
Interconnections can be made by soldering small wires to the 
pads or by wire wrapping or a combination of both. I recommend 
the latter method: solder all power and ground lines to the 
appropriate pins on the wire wrap IC sockets and wire wrap 
control, data and address lines. Locate 0.1uF capacitors at 
each IC package, connected between +5V and GND, to 
decouple power supply spikes and suppress high frequency 
oscillations on the supply. 

A suitable enclosure for the interface can be purchased 
from most electronic supply companies. It should be large 
enough to house a separate power supply which is required 
for operation of the interface. The circuit and power supply 
could also be mounted on a flat piece of material, such as 
aluminium or plexiglass, “open face” style. 

There are two basic options for handling the power supply. 
If you are planning to add more circuitry to your system later, 
you should buy or build a relatively high current power 
supply. A schematic for a +5V, ЗА power supply is shown in 
Figure 3. The regulated portion can be used to power the 
interface. The unregulated portion can be used to run the 
computer if you want to eliminate the standard calculator- 
type power supply. However, if you are not planning to add 
more active circuitry and you are satisfied with the calculator- 
type supply, you can get by without a separate supply. You 
will need though, a +5V voltage regulator to regulate the 
rough +9-11V going to the computer down to +5V for 
powering the interface which requires a total of about 
100mA. 


July/August 1981 


D6 3 
«TU D6 А Roy HS 


~<a | {> А/В SEL 
А1 
«c-r С sEL 
4 


i 


2-80 PIO 


о 
о 


со 
— 


о 
со 


z| 
| 
v 
Y А 
Е 25262536222 


OV 1 
— <=> GND 17 - 
1 


1 
Џ 
2X-80 / бабе | ~ 24 |26 


MicroAce and edge i +5ү 
computer connectors -І А 
| 1 (from Fig. 3) | > | 
Џ 
1 


! í | 
i Parallel interface board 16 pin DIP "Real world" 
‘connectors external 
device 


Figure 2. Schematic diagram of parallel interface circuit showing port A 
I/O lines being used as inputs and port B I/O lines as outputs. (Note: The 
software driver routine mentioned in the text assumes the opposite 
configuration; port A is output and port B is input.) 


51 ( +10 V 
wy 3 


PARTS LIST FOR POWER SUPPLY 


T1-18VCT 4A Transformer Radio Shack 273-1514 
D1,D2- 400 PIV 3A Silicon diodes 276-114 
RI- 1 ohm , 102, 10 watt resistor | 
010- 1М323 +5V regulator 

€1-4400 mF 25V electrolytic capacitor 
22-10 mF 25V tantalum capacitor 


C3-0.1 mF ceramic disc capacitor 


Figure 3. Schematic diagram of power supply used to operate the computer 
and the parallel interface circuit. 


39 


Figure 5. Тһе inside of the author’s system. The parallel interface and 
extra memory are located on the expansion board mounted above the 
computer. 


Figures 4, 5 and 6 are photographs of the author’s MicroAce 
system. The power supply provides unregulated +10V for 
the computer and 2K of on-board memory, and regulated 
+5V for the parallel interface plus an additional 6K of memory 
on the expansion board which is mounted just above the 
computer. The entire system is housed in a steel enclosure 
fitted with a hinged lid to which a standard size keyboard is 
mounted. The parallel port I/O (input/output) lines and 
handshake lines are brought out through two 16-pin DIP IC 
sockets. The cassette I/O connections are made available 
through two isolated phone jacks mounted on the front of the 
enclosure. Two RCA type phono jacks bring out the video 
signals: one for driving a standard video monitor and one for 
the RF modulator. Since the modulator is external to the 
computer, I use a TV as a video monitor for my other 
computer (Exidy Sorcerer). 


40 


Figure 4. Author’s 8K MicroAce system connected toa 
standard video monitor and standard size keyboard. 
The bread board in the foreground holds 16 LEDs 
which are used to monitor the outputs of both ports. 


Figure 6. The inside with the expansion board removed, revealing the 
computer board. 


Programming the PIO 

Since the ZX80 version of Basic offers no direct means of 
communication with an I/O device, a driver subroutine coded 
in Z-80 machine language must be loaded into memory to 
operate the PIO. Data and control words can be passed from 
Basic to the driver routine through the POKE instruction. 
The routine is executed by calling it with a USR instruction. 
Some knowledge of the Z-80 CPU instruction set is helpful in 
understanding the driver routine. 

Data is transferred from the CPU to the PIO by addressing 
one of its internal registers and writing to it by using one of 
the Z-80’s OUT instructions. We need only be concerned 
with four of the PIO registers in this application: port A 
control, port B control, port A data, and port B data. Each 
register is accessed by a unique address. I/O instructions are 
always associated with one-byte addresses comprised of the 


SYNC Magazine 


lower 8 bits of the address bus. A minimum of 3 address bits is 
required to operate the PIO. Normally, address line АО is 
connected to the port select line (B/A SEL) of the PIO and 
address line А1 is connected to the control/data select line 


(C/D SEL). The six remaining bits of the address byte are Address Meaning 

decoded to select one of a number of I/O devices. Since the 

PIO is the only I/O device in this system, decoding is not Binary Hexadecimal* Decimal* Contents of 

necessary. As shown in the schematic (Figure 2), address line Accumulator 

A7 is inverted and connected to the chip enable line (CE) of interpreted as... 

the PIO. Therefore, any address within the range 10000000B ІХХХХХ00 80 128 data — portA 

(B stands for binary) 11111111B will enable the PIO. The 1ІХХХХХО1 81 129 data — port B 

machine language driver routine (Figure 7) uses the “output IXXXXX10 82 130 control — port A 

immediate From Accumulator” instruction to transfer a byte IXXXXX11 83 131 control — port B 

of data to the PIO. This instruction is represented OXXXXXXX 00 0 PIO is not enabled, 

mnemonically no change 
OUT(n),A 

It transfers the contents of the Accumulator of the A register X means "don't саге”; this bit can be 1 or 0. * These values assume that 

(one of the Z-80 CPU internal registers) to the I/O device X —0. 

addressed by n. The table in Figure 8 gives the addresses of 

the PIO internal registers and their significance when using Figure 8. 


the OUT immediate instruction in this configuration. 


Label Location Machine code Mnemonic Comment 
(Dec) (Hex) 
0 0 00 NOP Do nothing. 
1 0 00 МОР Do nothing. 
2 62 ЗЕ. LD A, СЕН Load register A with operating 
3 207 СЕ mode control word. 
4 211 D3 OUT (82H), A Send control word to port A 
5 130 82 control register. 
6 62 ЗЕ LD A, 00H Load register A with data 
7 0 00 direction word. All lines output. 
8 211 D3 OUT (82H), A Send data direction word to 
9 130 82 port A control register. 
10 62 ЗЕ LD А, СЕН Load register A with operating 
11 207 СВ mode control word. 
12 211 D3 OUT (83H), А Send control word to port B 
13 131 83 control register. 
14 62 3B LD A, FFH Load register A with data 
15 255 ЕЕ direction word. АП lines input. 
16 211 D3 OUT (83H), A Send data direction word to 
17 131 83 port B control register. 
18 62 JE LD A, 07H Load interrupt control word. 
19 07 07 
20 211 D3 OUT (82H), A Send interrupt control word to 
21 130 82 port A control register. 
22 211 D3 OUT (83H), A — Send interrupt control word to 
23 131 83 port В control register. 
24 201 C9 RETN Return to Basic program. 
22 62 ЗЕ LD A, 00H Load register A with the 
26 00 00 contents of this location. 
27 211 D3 OUT (80H), A Send contents of register A 
28 128 80 to port A data register. 
29 201 C9 RETN Return to Basic program. 
30 33 21 LD HL,, 0000H Clear the HL register pair. 
31 0 00 
22 0 00 
23 14 ОЕ LDC, БІН Load register with port B 
34 129 81 data register address. 
35 231 ED IN L, (C) Read port B I/O lines. Load 
36 104 68 data into register L. 
37 201 C9 RETN Return to Basic program. 
СС „ЭА А ee a ee Е EE SEEE O 
Figure 7. 


July/August 1981 41 


Before data сап be sent through a port, certain control 
words must be loaded into the internal registers of the PIO. 
This process is called initialization, and the code that does 
this is called the initialization routine. Several things must be 
done in the initialization process: the operating mode must be 
set, the data direction must be established, and the interrupt 
servicing must be taken care of. In this example the selection 
of mode 3 simplifies matters since the handshake lines are not 
used. The operating mode is selected by writing a control 
word with the four least significant bits set high. The two 
most significant bits determine the opterating mode and the 
other two bits are not used as shown in Figure 9. 


Operating Mode Control Word 
Binary Hexadecimal Decimal 
Output О OOXX1111 0 15 
Input 1 OIXX1111 4F 79 
Bidirectional 2 10XX1111 SF 143 
Control 3 11XX1111 CF 207 
Figure 9. 


When the control mode (mode 3) is selected for a particular 
port, the next control word sent to that port will define the 
direction of data transfer on each of the port’s I/O lines. Each 
line corresponds to a bit position in the control word; the 
most significant bit of the control word corresponds to the 
most significant I/O line. A high condition (1) means input 
and a low condition (0) means output. For example, suppose 
the control word FOH (H stands for hexadecimal) is used to 
select data direction on the port B. Lines PBO through PB3 
would be set up for output while lines PB4 through PB7 
would be set up for input. 

Interrupts are handled very conveniently in this application; 
they are disabled by simply writing 07H (00000111B) to the 
control registers in both ports. 

The PIO machine language driver routine listed in Figure 
7 may be located in the unused spare portion of memory. 
However, in order to save the driver on cassette tape it must 
be located in the variables area of memory which is located 
immediately following the user Basic program. (When a program 
is stored on tape only the program itself, system variables and 
program variables are saved; not all of memory.) The two 
memory locations 16392 and 16393 contain the low byte and 
high byte, respectively, of the starting address of the variables 
area. This address will be referred to by the symbol ORG 
which stand for origin. Since the value of ORG depends on 
the size of the Basic program, all addresses in the driver 
routine must be relative to ORG. 

The driver consists of three machine language subroutines, 
each ending with a return from subroutine instruction. The 
first routine initializes the PIO, setting up port A for output 
and port B for input. (Note: This is opposite to what is shown 
in the schematic diagram of the parallel interface. This means 
that the switches should be connected to port B and the 
inverter-buffer inputs should be connected to port A.) The 
interrupts are disabled in the last portion of the initialization 
routine. Another routine sends a selected byte of the port A 
output routine. It is altered by the execution of a POKE 
instruction in the Basic program. The third routine, the port 
B input routine, reads the data present at the port B I/O lines 
and stores the information in the L register. The HL register 
pair is cleared, set to 0, at the beginning of the routine. 
Storing the data in the L register is convenient because, when 
a USR function is called, the value of the HL register pair is 
returned. For example, suppose that during execution of a 
Basic program the statement LET X=USR(Z) is encountered, 


42 


where Z is equal to the starting address of a machine language 
routine that merely loads the value 31264 in the HL register 
pair. The variable X would then be equal to 31264 after the 
completion of the machine language routine. If the HL register 
pair was not altered during the routine, X would equal Z. 

The Basic program that calls the driver routine must provide 
a means of entering the machine language code. Getting the 
code into the variables area is done by setting up an array, 
i.e., allocating a portion of memory (large enough to hold the 
driver) with a DIM statement. Getting the proper code into 
the array can be done in several ways. The simplest is to enter 
the elements as signed integers. Be aware that the integers 
are stored in two bytes of memory, with the less significant 
byte first. This makes it very difficult to decipher the machine 
code. A more elaborate method involves writing a Basic 
monitor which would include a hexadecimal-to-decimal routine 
and a decimal-to-hexadecimal routine for entering and displaying 
one-byte entries in hexadecimal notation. This would require 
perhaps more memory than a 1K machine could accommodate, 
but inspection and modification of the machine code would 
be much easier. The Basic program in Figure 10 employs the 
former method for entering the code. 


10 DIM MCZO) 
20 LET Vzl16392 

30 LET ОББ=РЕЕК (V0 +РЕЕК (V+1) #25642 
40 LET @0s0RG+25 

50 LET BI-ORGeZO 


60 LET MLA=AC+ i 


70 PRINT 
BO PRINT 
90 PRINT 


1900 PRINT "MENU" 
120 PRINT "1) INFUT CODE" 
150 PRINT "2) REVIEW CODE" 
140 PRINT °"3) FORT eA GUT" 
150 PRINT "4) FORT -B- Th" 
160 INFUT à 
170 LET ба Жі ООО 
180 CLS 
i720 GOSUB а 
jooo0 FOR Io TO 20 
того PRINT I 
10940 INFUT MIO 
1060 NEXT I 
Logo RETURN 
20900 FOR 121 TO 20 
голо PRINT I+GRG,FPEER (1+0RG),1+0RG+21, 
PEER (i+0ORGt21) 
зоо NEXT I 
2060 INFUT 2% 
гово RETURN 
2000 PRINT "ENTER BYTE OUT" 
2020 INFUT В 
S040 FORE MLA, Е 
aUOSO0 LET *=U5R (ORG) 
JOBO LET Х=ОВЕ taco 
2100 FRINT "ANOTHER BYTE 7" 
S120 INFUT 2% 
S140 CLS 
21609 ТЕ МОТ Z$-"" THEN RETURN 
2180 GOTO 2000 
4000 PRINT "HIT МЕМ LINE TO READ FORT B" 
4020 INPUT 2% 
4040 CL 3 
4oà60 IF NOT Z$-"" THEN RETURN 
2080 LET X=USR ЈЕО) 
4100 LET X-USRt(BI 
4120 FRINT "рата AT FORT В... "Хх 
4140 8070 4000 


ги 


Figure 10. 


SYNC Magazine 


This Basic program is menu-driven, giving the user the 
following options: entering the machine code, reviewing or 
listing the machine code, entering the byte to be sent out 
through the port A I/O lines, and reading the data present at 
the port B I/O lines. The variables used in the program are 
listed in Figure 11. The Sinclair version of integer Basic 
allows variables to be used as labels for GOTO and GOSUB 
statements. This feature is absent from many “expensive” 
versions. 


Variable Meaning 

ORG Beginning of driver routine. 

AO Beginning of port A output routine. 

BI Beginning of port B input routine. 

MLA Location of byte to be output through port A. 
У,У-+1 Points to the beginning of the variables area. 


Figure 11. 


Remember, when you get the driver routine loaded into 
memory, either by hand or by tape, do not press RUN. 
Instead, press GOTO followed by a number less than or equal 
to the lowest line number. GOTO 1 is safe. 

Operation of the program is straightforward. The user is 
first shown a menu and is prompted to input a number 
between 1 and 4. If 1 is entered, the user is prompted to enter 
the signed integer elements which comprise the machine 
code. In this program the user should respond with the 
following integers. The screen is cleared after each entry. 


Display Enter Display Enter 
0 0 10 -32045 
1 -12482 11 -31789 
2 -32045 12 16073 
3 62 13 -11386 
4 -32045 14 -13952 
5 -12482 15 33 
6 -31789 16 3584 
7 -194 17 -4735 
8 -31789 18 -13976 
9 1854 19 0 

20 0 

Figure 12. 


Item 2 on the menu displays the contents of the array in 
which the driver routine is buried. Item 3 asks the user to 
input an integer, between 0 and 255, to be output through the 
port A I/O lines. For example, if the integer 255 is entered, all 
eight I/O lines will be set high; if 0 is entered, all lines will be 
set low. Selection of item 4 will read the port B data present 
at the port B I/O lines. If lines 0 and line are high and the 
others connected to ground, the decimal value “129” will be 
displayed. One way to exit the program is to break (hit the 
space key) while the screen is blank. Another way is to enter 
the letter “7” when the computer is expecting an integer 
input, indicated by the appearance of the cursor in 
inverse video. 


Applications 

The number of possible applications for the ZX80/MicroAce 
with a parallel interface is limited only by the user’s imagination. 
With 16 I/O lines, interfacing devices such as A/D (analog to 
digital) and D/A (digital to analog) converters to the computer 
is a possibility perhaps once thought unachievable by many 
ZX80/MicroAce owners. Control of high voltage-current devices 
is also possible with relays and relay driver circuits. 

With an A/D converter one could realize an inexpensive 
data acquisition system for monitoring and recording various 
quantities in the laboratory, in industry, or in the home. For 


July/August 1981 


instance, a temperature to voltage or temperature to current 
converter could be connected to the A/D for recording 
temperatures over a period of time at specified intervals. The 
calibration could be done in software to reduce hardware 
costs. Of course, a simple voltmeter would also be a useful 
application. 

A programmable voltage source or power supply could be 
constructed by connecting a D/A converter to the parallel 
interface. Complex waveforms can be generated by cycling 
through a table of data words to be output by the D/A thus 
providing the user with a programmable function generator. 
An A/D converter can even be realized by using а D/A and a 
voltage comparator in a configuration known as a successive 
approximation A/D converter. 


High 
voltage 
source 


High 
voltage 


PARTS LIST FOR HIGH VOLTAGE-CURRENT CONTROL CIRCUIT 


Rl- 220 ohm 1/4watt resistor = 
R2- 2.2K onm 1/4watt resistor 
- TIL113 optical coupler 
01- 2N3055 transistor 
01- 1N4001 diode 


11- Relay (Potter-Brumfield KRP11DG) 


Figure 13. Schematic diagram of relay and computer controlled, optically 
isolated relay driver circuit. 


Figure 13 shows a circuit that enables computer control of 
high voltage-current devices such as televisions, coffee makers, 
and lights, (NOTE: Use caution if you decide to build this 
circuit. All high voltage wires and connections should be 
isolated and insulated from the user and the computer circuits). 
In this circuit an output line from one of the inverting buffers 
is used to drive an optically isolated relay driver circuit. An 
optical coupler with a darlington transistor output is used to 
isolate the computer circuits from any high voltages which 
may appear. The darlington output provides higher current 
driving capability than a standard, single transistor optical 
coupler but at the sacrifice of speed which is of no consequence 
in this application. Any comparable relay with a 12 VDC coil 
will also work. Be sure to stay within the current ratings of the 
contacts, however. Relays with other DC (direct current) 
voltage ratings will also work with appropriate resistor-value 
substitutions in the circuit. 

As I said, the possibilities are limitless. You may decide to 
just let the computer turn on LEDs in random sequence. At 
any rate, I hope you will experiment and share your discoveries 
with others via SYNC. 


Selected References 
1. Artwick, Bruce. Microcomputer Interfacing. Prentice-Hall, 1980. 


2. Barden, William Jr. The Z-80 Microcomputer Handbook. Howard 
W. Sams and Co., 1979. 


3. Engineering Staff on Analog Devices, Inc. Analog-Digital Conversion 
Notes. Analog Devices, 1976. 


4. Nichols, Elizabeth; Nichols, Joseph; Rony, Peter. Z80 Microprocessor 
Programing and Interfacing. Books 1 and 2. Howard W. Sams and Co., 
1979. 

5. Salt, Alger. “Build Additional RAM.” Syntax 2, no. 3 (March 1981). 

6. Z80 Assembly Language Programming Manual. Zilog, 1977. 


7. 2-80-РТО Z80A-PIO Technical Manual. Zilog, 1977. 
See SYNC NOTES for a P.S. from the author. 


43 


receptical 


If you have spent much time looking at 
the schematic for your ZX80 or MicroAce, 
and if you have had the opportunity to 
compare it with schematics for other home 
computers, you probably have noticed 
that there are considerably fewer parts. 
This is due to the efficiency of circuit 
design in several areas. One of these areas 
involves the absence of separate character 
generator ROMs in the video circuitry. 

The character generator is contained 
in the same ROM that holds the Basic 
interpreter. Sixty-four eight byte blocks 
are located in addresses 3584 to 4095 (0Е00 
to OFFF hex). While the Z X80 is in the 
video display mode, the CPU is addressing 
these memory locations and loading the 
data into IC9 (U10 for MicroAce). This 
data transfer is parallel, or eight bits at a 
time. The data is then shifted serially, or 
one bit at a time. These bits go to the 
video modulator which causes either light 
or dark spots on screen, depending on 
whether the bit is a *one" or "zero." The 
IC21 (U14) keeps track of which byte is 
to be addressed by counting up to eight 
horizontal sync pulses to determine which 
of the eight horizontal lines for each 
character is being displayed. 

You can examine each of the 64 char- 
acters in more detail by using the following 
program. 


10 INPUT AS 

20 LET A=(CODE CAS) жб) +5584 
50 FOR X=@ TO 7 

40 LET С=РЕЕК (A+X) 

50 FOR Y=@ TO 7 

БО LET Ес2жж(7-Ү) 

70 IF С=Е ОК DE THEN GO ТО 100 
8 PRINT " "3 

за GO TO 120 

100 LET С-С-Е 

110 PRINT СНК$ (128); 

120 МЕХТ У 

1:20 PRINT 

140 NEXT X 


PRESS RUN and NEWLINE. Then press 


any Key and NEWLINE. 


Dennis Duke. 716 Torri Ct.. Aledo. TX 76008. 


44 


Mini-Billboard 


Dennis Duke 


HE HL» 
= TM 


Press RUN and NEWLINE. Then press 
any key and NEWLINE. 

Line 20 converts the character A$ into 
the address of the first byte for that 
character in ROM. Line 40 sets C equal 
to the decimal value of that byte which is 
between 0 and 255 inclusive. In the first 
pass of the FOR-NEXT loop in lines 50 to 
120, C is examined to determine if the 
most significant bit (MSB) of the data is a 
"one" or a "zero." If the MSB is a “zero,” 
a space is printed. If the MSB is a “опе,” 
an inverse space is printed. In the next 
pass, the second most significant bit is 
examined and printed. The last pass will 
examine and print the least significant 
bit. 

After eight bits have been printed, line 
130 causes a new line so the next byte can 
be printed directly below the first. The 
FOR-NEXT loop in lines 30 to 140 causes 
eight bytes from sequential addresses to 
be printed. 

The addition of another FOR-NEXT 
loop, an array, and some other modifica- 
tions to this program allows us to print an 
eight character string on two rather large 
lines to create a "Mini-Billboard" on the 
TV screen. 


Mini-Billboard 


5 DIM AtS) 
10 INPUT AS 
15 FOR Ісі TO & 
20 LET ACT) =CCODE (A$) ж8 3 +5584 
21 LET AS=TLS CAS) 


TU 7 

TO L 

; PEEK (ACI}+X) 
од FOR Y=0 TO 7 
—Z*xekRC7-Y) 

70 IF C=E OR COE THEN GO TO 100 
ЕЙ PRINT " "; 

30 GO TO 128 

100 LET C=C-E 

110 PRINT СНК C129) 5 

120 NEXT Y 

150 NEXT I 

140 NEXT X 

150 LET Е=Е+4 

1&0 LET ізі зд 

170 IF L-& THEN GO TO 30 


Hou Uw n m: 
то ~ 


C4 
S 
n 
О 
ж 
(e зе Го 


Press RUN and NEWLINE. Then enter 
READ SYNC (or any two four letter words) 
and NEWLINE. 

You probably noticed we no longer 
need a PRINT statement in line 130 since 
four groups of eight characters are now 
printed in a line which will cause an 
automatic new line by coming to the end 
of a 32 character line. If you want to use 
a different graphic, change the number in 
line 110. Try also 7, 136, 8, and 223. 

So now you have a program which will 
print two large, four letter words on your 
TV screen. This may lead to some inter- 
esting suggestions from your friends, but 
have fun with it anyway. "n 


SYNC Magazine 


Hardware Review 


Anyone with a Sinclair or MicroAce has experienced the 
hassle of having to check the TV screen after every entry to 
see if it got into the machine. Of course, there are those 
people with good peripheral vision who can manage this feat 
without bobbing their heads, but not me. So when I saw an ad 
for a “keyboard beeper,” I realized this most certainly would 
be a big help in entering programs on the membrane keyboard 
and sent for one. 


The beeper comes assembled and is extremely simple. It 
consists of two integrated circuits, two resistors, and a capacitor 
mounted to a P.C. board barely larger than the components. 
The power and ground wires are connected to the ZX80 
board just below the modulator on some wide power traces. 


Joe Utasi, 2028 Knightsbridge Dr., Cincinnati, OH 45244. 


Keyboard Beeper 


Joe Utasi 


Five wires (which were twisted into a bundle) go to the 
keyboard side of the five pullup resistors at the extreme lower 
left side of the board. The order of sequence does not matter, 
as long as you connect to the side of the resistors that goes to 
the keyboard and not power. It is easy to see which side goes 
to the keyboard by just following the traces. 

The last step is to install the small round piezo-electric 
transducer which produces the sound. The directions provided 
with the beeper suggest soldering one edge to the top of the 
modulator (the left side), so that is where I put it. The one 
remaining wire from the beeper board is soldered to the 
white portion of the transducer. I used a piece of carpet tape 
(not included in the package) to mount the beeper to the 
inside of the case top on the front surface of the "blister." 

The beeper worked perfectly the first time. Slight changes 
in the tone of the beep for different keys can be detected. 
This might be an asset if you have a good ear. 

The real advantage comes when entering SHIFTed com- 
mands. Programming seems to go faster with less aggravation 
now that I know I am making good "contact" with the 
keyboard. I would certainly recommend the beeper as a 
definite improvement to the ZX80. 

Keyboard Beeper, $12. 

Burnett Electronics 

908 Morris St. 

Cincinnati, OH 45206 »" 


The Colossal Computer Cartoon Book 


Do 
Computer 


Enthusiasts 
Have 
More 


The best collection of computer cartoons ever is now in 
its second printing, and sports a bright new cover. The 
fifteen chapters contain hundreds of cartoons about 
robots, computer dating, computers in the office, home, 
and lab, and much more. 36 cartoonists share their views of 
man's ultimate machine. 


Keep this book with your reference works. When 
needed, the right cartoon can say it all for you. When you 
need a break from debugging a good laugh can give you a 
welcome lift. Recommended for hours of fun and comic 
insight. 


Edited by David Ahl, mastermind behind the April Fool's 
issue of Dr. Kilobyte's Creative Popular Personal Re- 
creational Micro Computer Data Interface World Journal, 
this cartoon book contains much of that same incurable 
zaniness. [Want this issue? It's April 1980 and only $2.50 
postpaid]. 


ITS TIME 


E 
FICTION PROGRA 
ON TV. 


an " 
FOR ? 
YOUR FAVORITE SCIENCE | 
м . 
N | 


THE ROBOTS 
NEVER WIN. 
| о 
| 


А large 8' x 11" softbound collection of 120 pages, it still sells for only $4.95. (6G). 


July/August 1981 


Hardware Review 


SK Basic ROM 


David Lubar 


While the 4K Integer Basic in the Sinclair 
ZX80 is adequate for many applications, 
most programmers will eventually feel a 
hunger for more power. True, advanced 
functions can be simulated by way of 
subroutines, but such measures eat memory 
at an alarming rate. Enter the 8K Basic 
ROM. The chip costs a mere $39.95, which 
is an extremely low price for any ROM. 
Some versions of Basic are sold for over 
$200 on disk. Sinclair gets four stars for 
not robbing its customers. 


Plugging In 

Installing the ROM chip requires opening 
the Sinclair. Most owners have probably 
already done this out of curiosity and 
learned that nothing disasterous follows. 
One really has to go out of his way to hurt 
the little critter. The only problem is dealing 
with the plastic pins which hold the case 
together. Once the case is open, the old 
ROM has to be removed. This requires 
some patience. If a chip is pulled with 
unequad pressure, the pins can be bent. 
It’s best to keep the old ROM intact, for 
reasons that will be covered later. The 
new ROM is installed by lining up the 
pins and exerting gentle pressure. Next, a 
new keyboard overlay is put in place. 
This overlay contains letters, numbers, 
keywords, graphics symbols and functions, 
with color coding to aid the confused. 
Once the ROM has been tested by power- 
ing up the computer, the case can be 
replaced. 


Features 

With the ROM installed, the Sinclair 
has floating point capability. It can handle 
decimals with nine-place accuracy. Other 
added functions include string and numeric 
arrays of any dimension, trig functions, 
and extended string functions. The PLOT 
and TAB commands allow formatting of 
text and graphics. Unfortunately, the 
proposed DRAW command, which would 
have drawn a line between any two sets 
of coordinates, was not included in the 
final version of the Basic. 


46 


As before, keywords are obtained with 
a single stroke. By hitting the FUNCTION 
key, the user can also obtain functions 
with one keystroke. Don’t get excited about 
the commands FAST and SLOW. The 
Sinclair already operates in the FAST 
mode. The SLOW mode (to eliminate 
flicker of the display) only works on the 
ZX 81, which is not yet available in the 
U.S. There is a SCROLL command, which 
moves the screen display up one line. 
The computer will still crash if you attempt 
to write beyond the screen. 

Several commands have been provided 
for use with the printer Sinclair plans to 
introduce. The user will be able to send 
listings to this printer and to print. the 
contents of the screen. For interactive 
programs, there is an INKEY$ command. 
This reads the keyboard without requiring 
NEWLINE. The pause command sends 
the contents of the display list to the 
screen and waits a specified amount of 
time. This allows for limited animation, 
but still produces a flicker. All in all, the 
8K Basic greatly expands the potential of 
the Sinclair. 


Compatability 

The 8K ROM contains an improved set 
of tape routines. While this means that 
loading and saving should be less hassle, 
it also means that you can’t load old- 
ROM tapes into a new-ROM machine. 
And even if you could load such programs, 
they wouldn’t run. This means most users 
will be doing a lot of translating. Two 
major differences must be kept in mind. 
First, many programs took advantage of 
the Integer Basic, ignoring the remainder 
after division. To simulate this in the new 
Basic, use the INT function. Secondly, 
where the Integer Basic ROM used minus 
one for true when evaluating logical 
operations, the 8K ROM uses positive 
one. Any calculations based on logical 
operators will require a sign change during 
translation. 

Ideally, it would be nice to be able to 
switch from one ROM ю the other. 


Someone is bound to produce such a switch 
in the near future and many enterprising 
hobbyists are likely to design their own. 
While such a switch would clobber anything 
in memory, it would allow loading of either 
flavor of tape without pulling and replacing 
chips. For this reason, it is advisable to 
hold onto the old ROM. 

The most noticable difference between 
the ROMs occurs when you try entering 
a 1K program. The new ROM uses about 
100 bytes more of RAM than the old 
ROM. Most programs that fit into 1K 
before won't fit now. To get any value 
out of the new Basic, a user should have 
at least 2K, preferably 16K. 

So, if you are feeling limited by 4K 
Basic, and either plan to expand memory, 
or already have, then the 8К Basic ROM 
is an excellent way to extend the capabilities 
of your Sinclair. The 8K Basic ROM is 
available for $39.95 plus $4 shipping from 
Sinclair Research Ltd., 1 Sinclair Plaza, 
Nashua, NH 03061. | 


ЕТІЛ СР 


This column will feature short programs 
to show off your ZX80, impress your family 
and friends, and tickle your imagination 
when SYNC arrives at your place. We 
invite your contributions. Address them 
to SYNC, 39 E. Hanover Ave., Morris 
Plains, NJ 07950. 


10 LET M=16567 
20 FOR A=386 TO 419 
30 POKE M+A-386,PEEK(A) 


40 NEXT А 
50 POKE М-ҒА-386,201 


60 ҒОК А-0 ТО 32767 
70 PRINT A 
80 LET B=USR(M) 
90 CLS 
100 NEXT A 


Notes: 
10 A few bytes after DF-END 
20 Section in Basic to turn on screen 
50 Return at end 
Enter RUN and NEWLINE. You will have 
to adjust the screen to get as good a 
picture as possible, but it still will not be 
perfect. 
Our thanks to: 
David Goodrich 
124 NE Spruce 
Bartlesville, OK 74003 n" 


SYNC Magazine 


Software Review 


After the successful introduction of 
Super ZX80 Invasion, [see SYNC 3:5] 
Softsync has come out with Double Break- 
out, its second active display game. Double 
Breakout is just as much fun as Super 
Z X60 Invasion, and even more challenging. 
This, too, fits into 1К of memory. 

After loading the game from the cassette, 
the words “100 REM" appear at the top 
of your screen. Enter “СО TO 1" and 
then select your level of play. There are 
seven skill levels where 7 is slow enough 
for beginners, 4 is medium, and 1 is 
extremely fast for the expert. Softsync's 
brochure claims that you do not have a 
chance at level 1, but we have found that 
after extensive play you do have a good 
chance. 

A game field 31 spaces wide and 18 
spaces high appears on the screen. Within 
the area are two walls of blocks running 
vertically, each five rows thick. One is in 
the middle of the screen, and the other is 
off to the right. The paddle appears in the 
upper left hand corner of the screen and 
can be moved up and down along the left 
side by using the arrow keys (5 and 8). 
The makers recommend that your com- 
puter be turned sideways so the keys will 
face up and down according to the move- 
ments of the paddle, but we suggest that 
you turn your television sideways if possible. 
The ball, represented graphically by the 
letter *0", bounces between your paddle 
and the blocks, each time chipping a block 
off the wall. Once you break through the 
first wall there is another wall which you 
must also knock out. 


David and James Grosjean, 50 Kings Rd., Chat- 


ham, NJ 07928. 


July/August 1981 


And the Walls Came > 


David апа James 
Grosjean 


You have nine balls with which to knock 
out the blocks. The number of balls 
remaining is displayed in the left hand 
corner of the screen, just outside of the 
playing area. Each time you miss the ball, 
the number diminishes by one, and the 
next ball is served immediately. If you 
lose all the balls, a new game is started, 
and, if you successfully clear out all the 
blocks, the ball continues to bounce 
around. 


Q 
%у, Ming 
Down 


You cannot stop the game to change 
skill levels during play. The BREAK key 
does not function. You must unplug the 
machine and reload the game. 

By deleting line 100, the portion of the 
program written in Basic is revealed. This 
is the part which asks for the ball speed 
and then calls a machine code subroutine 
which actually plays the game. Line 450 
of the program makes sure you do not 
enter a speed slower than 7 or faster than 
1. If you delete this line, you can enter a 
speed slower than 7. The game will run 
the same as before even with line 100 
missing. 

For those of you who play the original 
arcade Breakout games by Atari, here 
are a few comparisons: The name Double 
Breakout does not mean two balls and 
two paddles, like Atari’s, but two walls of 
blocks. This could be confusing. In Atari’s 
arcade Double Breakout, the ball increases 
speed as it hits more blocks, but in this 
Double Breakout the speed you choose 
at the beginning of the game remains the 
same. Softsync's Double Breakout gives 
nine balls with automatic serving, while 
the arcade game gives only three balls 
with manual serving. Double Breakout 
serves a new ball as soon as one is lost, so 
on level 1, if a ball is lost, the next one 
will be served so quickly, that you might 
not be able to get to it in time return it. 

One shortcoming of the game is that 
there is is no scoring, and another is that 
there is no extended play such as extra 
balls or walls. 

Double Breakout is another break- 
through in creating active display games 
for the ZX80. We had great fun playing 
Double Breakout and are amazed at how 
much they fit into 1K. a” 


47 


ДЕ | | {в = — ПО 


Software 


ZX80/MicroAce software on cassette: 
Dragon Castle Adventure, Betting Sys- 
tem for Horse Players, Robot Composer, 
and ESP Guessing; all 4 for $10. 

Cecil Bridges 

1248 N. Denver 

Tulsa, OK 74106 


Three cassette tapes: (1) Slot Machine, 
Robot Fight, Corporation, Tank Battle; 
(2) Lucky Lindy, Crop Duster, Nuke 
Em, Carrier Landing; (3) The Pharaohs 
Treasure; $10 each. 

Tensor Technology Inc. 

P.O. Box 17868 

Irvine, CA 92713 


Smart Reversi | Othello]. Play the classic 
game against your Z X80. Uses a very 
strong move algorithm extracted from 
a much larger program; game board 
display. (Othello [R] is.a trademark of 
CBS Toys, Inc.) $6. £3.50 (U.K.) 

C. W. Percival 

193 Peaceable St. 

Ridgefield, CT 06877 


The ZX80 Companion is now available 
with a 20 pp. supplement for the 2.Х81. 
The supplement is available separately 
for £1.50. 

Linsac 

68 Barker Road 

Linthorpe 

Middlesbrough, Cleveland, TS5 5ES 

England 


ZX80 Multiple Line Statements 
Easy, Useful Programming Trick. 
Saves memory, runs faster. Details £1 
inc. postage (U.K.) or $2.50 inc. airmail 
(USA). 

Tim Humphries 

16 Coniston Road 

Sutton Coldfield 

West Midlands 

England 


ZX60 Graphics; 48 pp. containing pro- 
gramming techniques and 6 original pro- 
grams; $8 incl. postage. 

SUMWARE 

P.O. Box 30 

Shawville, PA 16873 


48 


ZX80/1 Record; a tape record system 
to save, load, or enter new 96 byte 
records; ideal for addresses; for all ІК 
machines (4K/8K КОМ); £3; $9. Direc- 
tory; a simple program to read tapes 
and display program names; (8& ROM); 
£2; $6. 

Logan Software 

24 Nurses Lane 

Skellingthorpe 

Lincoln LN6 OTT 

UK 


Music cassette: Side A: Player ZX80; 
Side B: space MUSE-AK, a random 
sound program. Prepaid orders; $6.95 
postpaid ($10 outside the U.S.). Other 
programs available. 

William Don Maples 

688 Moore St. 

Lakewood, CO 80215 


5 cassettes: (1) Games; (2) Junior Edu- 
cation; (3) Business and Household; (4) 
Games; (5) Junior Education; £3.95. 
Designed for the 7Х81, but many will 
run on the ZX80 with SK ROM; some 
need the 16K RAM pack. Cheque/PO; 
Access/Barclaycard. 

Sinclair Research 

FREEPOST 7 

Cambridge, CB2 1YY 

UK 


® Microcomputer Index; subject index- 


ing of articles in 20 microcomputer peri- 
odicals. 
Microcomputer InformationServices 
2464 Е Camino Real 
Box 247 
Santa Clara, CA 95051 


Filing program “Мише”; £17.50. 
Machine code assembler “ZXAS” for 
ZX80 or ZX81 (specify); £3.95. 

Bug-Byte 

251 Henley Road 

Coventry CV2 1BX 

England 


Compute and display program (ІК & 
2K) with instruction booklet, coding 
sheets, and coding charts for ZX80 (4K 
ROM); £4.95. 

JRS Software 

19 Wayside Avenue 

Worthing 

West Sussex, BN13 3JV 

England 


e Wide range of games for ZX80/1 (4K 


& 8K ROM). 
Premier Publications 
12 Kingscote Road 
Addiscombe, Croydon, 
Surrey 
England 


e 2 versions of Defender with built in 


software to drive their soundboard (£25); 
£4.50 small screen; £5.50 large screen. 
Quicksilva 
95 Upper Brownhill Road 
Maybush, Southampton, 
Hants 
England 


Hardware 


Re-Zolv Resist. Used with positive or 
negative transparencies; circuit patterns 
can be drawn also; develops with water. 
For the hobbyist and the professional 
engineer. Starter kit: COD $13.40; $12 
for prepaid. Phone (217) 352-9336. 

Coval Industries, Inc. 

2706 W. Kirby Ave. 

Champaign, IL 61820 


MicroAce upgrade products: 
ЗК КОМ; $35. 
Video upgrade board for flicker free 
display (8K ROM required); $29.50. 
MicroAce 2K Computer Kit; $149. 
Planned for the fall: 16K RAM, $150; 
4K RAM, $110. 

MicroAce 

1348 E. Edinger 

Santa Ana, CA 92705 


Users Groups 


ZX80 Southeast Region Club 

869 Levitt Parkway 

Rockledge, FL 32955 

Newsletter planned beginning in August. 
Pres. Ralph Coletti. Inquiries from 
interested parties welcome. 


SYNC Magazine 


Se ad 


creative 
compating 


Creative Computing-- Albert Einstein in 
black on a red denim-look shirt with red 
neckband and cuffs. 


Га rather 
<> be playing 


l'd rather be playing spacewar-- black 
with white spaceships and lettering. 


Computer Bum-- black design by car- 
toonist Monte Woiverton on gray 
denim-look shirt with black neckband 
and cuffs. 


Creative’s own outrageous Bionic Toad 
in dark blue on a light blue shirt for 
kids and adults. 


Give your 
tie a rest! 


АП T-shirts are available in adult sizes 
S,M,L,XL. Bionic Toad, Program Bug and 
Spacewar also available in children's sizes 
5(6-8), M(10-12) and L(14-16). Made in USA. 
$6.00 each plus 75€ shipping. 

Specify design and size and send payment 
to Creative Computing, 39 E. Hanover Ave., 
Morris Plains, NJ 07950. Orders for two or 
more shirts may be charged to Visa, Master- 
Card or American Express. Save time and 
call toll-free 800-631-8112 (in NJ 201-540- 
0445). 


А 
> w S 
/ < F У 
/ ) ~ 9) C о ч 
ы B - зы AN 
——_ | fF - у; 3 
\ 3 1 n ^ 
£ - LA » 5 
d T e-—— Е: 
~ += = < "NS 
; \ у а à Se 
, : ^ ge C 4 
г Ча D Es 3 | Sa - 
P 3 aca S =; 
2 А. is = 
S == y i 
с не j 
\ 
Y j | 
М2 


Beware the 
Program BUG! 


from Katie and the Computer 


The Program Bug that terrorized Cyber- 
nia in Katie and the Computer is back 
on this beige t-shirt with purple design. 
You can share the little monster with 
your favorite kid. 


7171717171717171717171717171717171717171 
i M 2 2158374; 545254: . 4- RS. ;3 coe TF 


33333 


4935! 


3399393333333333323 
jidd3i3is333332223223432323 


047521620569660240580 035 | 
7T17171717171717171717171717171717171 


Plotter display of Pi to 625 Places in 
dark brown on a tan shirt. 


Crash Cursor and Sync from the comic strip 
in SYNC magazine emblazoned in white on 
this black shirt. 


Roll down the block with this little 
black Robot Rabbit (on a bright orange 
t-shirt) оп your back and you can 
intimidate every carrot, radish or cuke 
in your way. 


...А ЭСТЕМСЕ - 
FICTION 
CARTOON 
COMEDY 
SERIES IN 
EVERY ISSUE 


THRILL TO THE INSANE ADVENTURES OF -- 


" 
uin 


ні! 


17 


" 


Tut 


* «И 


PLUS: 
Articles, 
games, 
applications, 
reviews and 
MORE! 


Brought to you by the people at 


creabive compating 


SYNC is the dynamite bi-monthly magazine for users of the Sinclair 2Х80. The main 
focus is on applications, programming techniques, hints and tips for getting the most 
out of the ZX80. SYNC also reviews new peripherals, software and books for the ZX80. 

· Subscriptions to SYNC cost just $10 for Six bi-monthly issues (£10 in the U.K.). Send to 
SYNC, 39 E. Hanover Avenue, Morris Plains, NJ 07950, USA.